changeset 21855:c8456ff7a4c3 v8.2.1477

patch 8.2.1477: Vim9: error when using bufnr('%') Commit: https://github.com/vim/vim/commit/f39397e515067d5a314be99778e63fe0acf93c51 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Aug 17 22:21:36 2020 +0200 patch 8.2.1477: Vim9: error when using bufnr('%') Problem: Vim9: error when using bufnr('%'). Solution: Don't give an error for using a string argument. (closes https://github.com/vim/vim/issues/6723)
author Bram Moolenaar <Bram@vim.org>
date Mon, 17 Aug 2020 22:30:04 +0200
parents f324c9bc756d
children 9c11cd6eb442
files src/evalbuffer.c src/testdir/test_vim9_func.vim src/version.c
diffstat 3 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/evalbuffer.c
+++ b/src/evalbuffer.c
@@ -390,7 +390,8 @@ f_bufnr(typval_T *argvars, typval_T *ret
 	buf = curbuf;
     else
     {
-	(void)tv_get_number(&argvars[0]);    // issue errmsg if type error
+	if (argvars[0].v_type != VAR_STRING)
+	    (void)tv_get_number(&argvars[0]);    // issue errmsg if type error
 	++emsg_off;
 	buf = tv_get_buf(&argvars[0], FALSE);
 	--emsg_off;
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -1315,6 +1315,11 @@ def Test_filter_return_type()
   assert_equal(6, res)
 enddef
 
+def Test_bufnr()
+  let buf = bufnr()
+  assert_equal(buf, bufnr('%'))
+enddef
+
 def Test_getreg_return_type()
   let s1: string = getreg('"')
   let s2: string = getreg('"', 1)
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1477,
+/**/
     1476,
 /**/
     1475,