]> granicus.if.org Git - vim/commitdiff
patch 8.2.1550: Vim9: bufname('%') gives an error v8.2.1550
authorBram Moolenaar <Bram@vim.org>
Sun, 30 Aug 2020 19:26:57 +0000 (21:26 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 30 Aug 2020 19:26:57 +0000 (21:26 +0200)
Problem:    Vim9: bufname('%') gives an error.
Solution:   Only give an error for wrong argument type. (closes #6807)

src/evalbuffer.c
src/testdir/test_vim9_func.vim
src/version.c

index 2d738f12495c9bf60518d09df64ce233987031ac..5cf884a80cea668a53fe6b44308a65d2c34978d1 100644 (file)
@@ -359,15 +359,20 @@ f_bufloaded(typval_T *argvars, typval_T *rettv)
 f_bufname(typval_T *argvars, typval_T *rettv)
 {
     buf_T      *buf;
+    typval_T   *tv = &argvars[0];
 
-    if (argvars[0].v_type == VAR_UNKNOWN)
+    if (tv->v_type == VAR_UNKNOWN)
        buf = curbuf;
     else
     {
-       (void)tv_get_number(&argvars[0]);       // issue errmsg if type error
        ++emsg_off;
-       buf = tv_get_buf(&argvars[0], FALSE);
+       buf = tv_get_buf(tv, FALSE);
        --emsg_off;
+       if (buf == NULL
+               && tv->v_type != VAR_NUMBER
+               && tv->v_type != VAR_STRING)
+           // issue errmsg for type error
+           (void)tv_get_number(tv);
     }
     rettv->v_type = VAR_STRING;
     if (buf != NULL && buf->b_fname != NULL)
index 39382f3f7c71be4cb759b3b781e19d2abcb9d692..0d27f2ddbeba5f7454743293fb4bc0798b114abe 100644 (file)
@@ -1435,6 +1435,14 @@ def Test_setreg()
   assert_equal(reginfo, getreginfo('a'))
 enddef 
 
+def Test_bufname()
+  split SomeFile
+  assert_equal('SomeFile', bufname('%'))
+  edit OtherFile
+  assert_equal('SomeFile', bufname('#'))
+  close
+enddef
+
 def Fibonacci(n: number): number
   if n < 2
     return n
index d4bca788c52e4df6cbb1d1f12c10c080dda8136c..8e112994af91ce782d29a944a5e4157e98e9cc58 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1550,
 /**/
     1549,
 /**/