diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-03-28 21:14:06 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-03-28 21:14:06 +0200 |
commit | 3215466af9abfc9fbbfba81d166d625176993486 (patch) | |
tree | efe284b211209a60a72c4e04e18ed2fad90182fc | |
parent | b2cb6c8bbd215177ed05c1d952e7ef2ad8f7ef4b (diff) |
patch 8.2.2673: Vim9: script-local funcref can have lower case namev8.2.2673
Problem: Vim9: script-local funcref can have lower case name.
Solution: Require an upper case name.
-rw-r--r-- | src/evalvars.c | 6 | ||||
-rw-r--r-- | src/testdir/test_vim9_assign.vim | 26 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 32 insertions, 2 deletions
diff --git a/src/evalvars.c b/src/evalvars.c index cd50ba7fdd..e9e893a3f8 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -3453,8 +3453,10 @@ var_wrong_func_name( char_u *name, // points to start of variable name int new_var) // TRUE when creating the variable { - // Allow for w: b: s: and t:. - if (!(vim_strchr((char_u *)"wbst", name[0]) != NULL && name[1] == ':') + // Allow for w: b: s: and t:. In Vim9 script s: is not allowed, because + // the name can be used without the s: prefix. + if (!((vim_strchr((char_u *)"wbt", name[0]) != NULL + || (!in_vim9script() && name[0] == 's')) && name[1] == ':') && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':') ? name[2] : name[0])) { diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim index b9851a77f5..05e65e1ecf 100644 --- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -1654,5 +1654,31 @@ def Test_assign_command_modifier() CheckDefAndScriptSuccess(lines) enddef +def Test_script_funcref_case() + var lines =<< trim END + var Len = (s: string): number => len(s) + 1 + assert_equal(5, Len('asdf')) + END + CheckDefAndScriptSuccess(lines) + + lines =<< trim END + var len = (s: string): number => len(s) + 1 + END + CheckDefAndScriptFailure(lines, 'E704:') + + lines =<< trim END + vim9script + var s:Len = (s: string): number => len(s) + 2 + assert_equal(6, Len('asdf')) + END + CheckScriptSuccess(lines) + + lines =<< trim END + vim9script + var s:len = (s: string): number => len(s) + 1 + END + CheckScriptFailure(lines, 'E704:') +enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker diff --git a/src/version.c b/src/version.c index 602fdb622c..fe274258ed 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2673, +/**/ 2672, /**/ 2671, |