0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

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)
This commit is contained in:
Bram Moolenaar
2021-06-21 20:48:58 +02:00
parent cb54bc6562
commit 22f17a29cd
3 changed files with 22 additions and 1 deletions

View File

@@ -90,6 +90,24 @@ def Test_compile_error_in_called_function()
CheckScriptFailureList(lines, ['E1012:', 'E1191:']) CheckScriptFailureList(lines, ['E1012:', 'E1191:'])
enddef enddef
def Test_wrong_function_name()
var lines =<< trim END
vim9script
func _Foo()
echo 'foo'
endfunc
END
CheckScriptFailure(lines, 'E128:')
lines =<< trim END
vim9script
def _Foo()
echo 'foo'
enddef
END
CheckScriptFailure(lines, 'E128:')
enddef
def Test_autoload_name_mismatch() def Test_autoload_name_mismatch()
var dir = 'Xdir/autoload' var dir = 'Xdir/autoload'
mkdir(dir, 'p') mkdir(dir, 'p')

View File

@@ -3595,7 +3595,8 @@ trans_function_name(
lead += (int)STRLEN(sid_buf); lead += (int)STRLEN(sid_buf);
} }
} }
else if (!(flags & TFN_INT) && builtin_function(lv.ll_name, len)) else if (!(flags & TFN_INT) && (builtin_function(lv.ll_name, len)
|| (in_vim9script() && *lv.ll_name == '_')))
{ {
semsg(_("E128: Function name must start with a capital or \"s:\": %s"), semsg(_("E128: Function name must start with a capital or \"s:\": %s"),
start); start);

View File

@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
3031,
/**/ /**/
3030, 3030,
/**/ /**/