diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-08-30 21:26:57 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-08-30 21:26:57 +0200 |
commit | 02aaad91094939758e053588dd23ebda467eea29 (patch) | |
tree | 27b7e4bbe5b769297c905c1c4ff54e6ffa6c614c /src | |
parent | ca774f67534e6d1843fda9d1dc9a899972d27577 (diff) |
patch 8.2.1550: Vim9: bufname('%') gives an errorv8.2.1550
Problem: Vim9: bufname('%') gives an error.
Solution: Only give an error for wrong argument type. (closes #6807)
Diffstat (limited to 'src')
-rw-r--r-- | src/evalbuffer.c | 11 | ||||
-rw-r--r-- | src/testdir/test_vim9_func.vim | 8 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 18 insertions, 3 deletions
diff --git a/src/evalbuffer.c b/src/evalbuffer.c index 2d738f1249..5cf884a80c 100644 --- a/src/evalbuffer.c +++ b/src/evalbuffer.c @@ -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) diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim index 39382f3f7c..0d27f2ddbe 100644 --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -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 diff --git a/src/version.c b/src/version.c index d4bca788c5..8e112994af 100644 --- 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 */ /**/ + 1550, +/**/ 1549, /**/ 1548, |