Skip to content

Commit 3215466

Browse files
committed
patch 8.2.2673: Vim9: script-local funcref can have lower case name
Problem: Vim9: script-local funcref can have lower case name. Solution: Require an upper case name.
1 parent b2cb6c8 commit 3215466

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/evalvars.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,8 +3453,10 @@ var_wrong_func_name(
34533453
char_u *name, // points to start of variable name
34543454
int new_var) // TRUE when creating the variable
34553455
{
3456-
// Allow for w: b: s: and t:.
3457-
if (!(vim_strchr((char_u *)"wbst", name[0]) != NULL && name[1] == ':')
3456+
// Allow for w: b: s: and t:. In Vim9 script s: is not allowed, because
3457+
// the name can be used without the s: prefix.
3458+
if (!((vim_strchr((char_u *)"wbt", name[0]) != NULL
3459+
|| (!in_vim9script() && name[0] == 's')) && name[1] == ':')
34583460
&& !ASCII_ISUPPER((name[0] != NUL && name[1] == ':')
34593461
? name[2] : name[0]))
34603462
{

src/testdir/test_vim9_assign.vim

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,5 +1654,31 @@ def Test_assign_command_modifier()
16541654
CheckDefAndScriptSuccess(lines)
16551655
enddef
16561656

1657+
def Test_script_funcref_case()
1658+
var lines =<< trim END
1659+
var Len = (s: string): number => len(s) + 1
1660+
assert_equal(5, Len('asdf'))
1661+
END
1662+
CheckDefAndScriptSuccess(lines)
1663+
1664+
lines =<< trim END
1665+
var len = (s: string): number => len(s) + 1
1666+
END
1667+
CheckDefAndScriptFailure(lines, 'E704:')
1668+
1669+
lines =<< trim END
1670+
vim9script
1671+
var s:Len = (s: string): number => len(s) + 2
1672+
assert_equal(6, Len('asdf'))
1673+
END
1674+
CheckScriptSuccess(lines)
1675+
1676+
lines =<< trim END
1677+
vim9script
1678+
var s:len = (s: string): number => len(s) + 1
1679+
END
1680+
CheckScriptFailure(lines, 'E704:')
1681+
enddef
1682+
16571683

16581684
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2673,
753755
/**/
754756
2672,
755757
/**/

0 commit comments

Comments
 (0)