Skip to content

Commit 22f17a2

Browse files
committed
patch 8.2.3031: no error if a function name starts with an underscore
Problem: No error if a function name starts with an underscore. (Naohiro Ono) Solution: In Vim9 script disallow a function name starting with an underscore, as is mentioned in the help. (closes #8414)
1 parent cb54bc6 commit 22f17a2

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/testdir/test_vim9_func.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ def Test_compile_error_in_called_function()
9090
CheckScriptFailureList(lines, ['E1012:', 'E1191:'])
9191
enddef
9292

93+
def Test_wrong_function_name()
94+
var lines =<< trim END
95+
vim9script
96+
func _Foo()
97+
echo 'foo'
98+
endfunc
99+
END
100+
CheckScriptFailure(lines, 'E128:')
101+
102+
lines =<< trim END
103+
vim9script
104+
def _Foo()
105+
echo 'foo'
106+
enddef
107+
END
108+
CheckScriptFailure(lines, 'E128:')
109+
enddef
110+
93111
def Test_autoload_name_mismatch()
94112
var dir = 'Xdir/autoload'
95113
mkdir(dir, 'p')

src/userfunc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3595,7 +3595,8 @@ trans_function_name(
35953595
lead += (int)STRLEN(sid_buf);
35963596
}
35973597
}
3598-
else if (!(flags & TFN_INT) && builtin_function(lv.ll_name, len))
3598+
else if (!(flags & TFN_INT) && (builtin_function(lv.ll_name, len)
3599+
|| (in_vim9script() && *lv.ll_name == '_')))
35993600
{
36003601
semsg(_("E128: Function name must start with a capital or \"s:\": %s"),
36013602
start);

src/version.c

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

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3031,
758760
/**/
759761
3030,
760762
/**/

0 commit comments

Comments
 (0)