Skip to content

Commit 02aaad9

Browse files
committed
patch 8.2.1550: Vim9: bufname('%') gives an error
Problem: Vim9: bufname('%') gives an error. Solution: Only give an error for wrong argument type. (closes #6807)
1 parent ca774f6 commit 02aaad9

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/evalbuffer.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,20 @@ f_bufloaded(typval_T *argvars, typval_T *rettv)
359359
f_bufname(typval_T *argvars, typval_T *rettv)
360360
{
361361
buf_T *buf;
362+
typval_T *tv = &argvars[0];
362363

363-
if (argvars[0].v_type == VAR_UNKNOWN)
364+
if (tv->v_type == VAR_UNKNOWN)
364365
buf = curbuf;
365366
else
366367
{
367-
(void)tv_get_number(&argvars[0]); // issue errmsg if type error
368368
++emsg_off;
369-
buf = tv_get_buf(&argvars[0], FALSE);
369+
buf = tv_get_buf(tv, FALSE);
370370
--emsg_off;
371+
if (buf == NULL
372+
&& tv->v_type != VAR_NUMBER
373+
&& tv->v_type != VAR_STRING)
374+
// issue errmsg for type error
375+
(void)tv_get_number(tv);
371376
}
372377
rettv->v_type = VAR_STRING;
373378
if (buf != NULL && buf->b_fname != NULL)

src/testdir/test_vim9_func.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,14 @@ def Test_setreg()
14351435
assert_equal(reginfo, getreginfo('a'))
14361436
enddef
14371437

1438+
def Test_bufname()
1439+
split SomeFile
1440+
assert_equal('SomeFile', bufname('%'))
1441+
edit OtherFile
1442+
assert_equal('SomeFile', bufname('#'))
1443+
close
1444+
enddef
1445+
14381446
def Fibonacci(n: number): number
14391447
if n < 2
14401448
return n

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1550,
757759
/**/
758760
1549,
759761
/**/

0 commit comments

Comments
 (0)