# HG changeset patch # User Bram Moolenaar # Date 1624302003 -7200 # Node ID 494112d2aa93ead9960e07b97391b2684ffe1db6 # Parent 5a15a7f25ff270b674fb9efac772039ca84c2b0f patch 8.2.3031: no error if a function name starts with an underscore Commit: https://github.com/vim/vim/commit/22f17a29cd0b0cc3107dc6cd1d96c62eee52a7d9 Author: Bram Moolenaar Date: Mon Jun 21 20:48:58 2021 +0200 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) diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -90,6 +90,24 @@ def Test_compile_error_in_called_functio CheckScriptFailureList(lines, ['E1012:', 'E1191:']) 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() var dir = 'Xdir/autoload' mkdir(dir, 'p') diff --git a/src/userfunc.c b/src/userfunc.c --- a/src/userfunc.c +++ b/src/userfunc.c @@ -3595,7 +3595,8 @@ trans_function_name( 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"), start); diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -756,6 +756,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3031, +/**/ 3030, /**/ 3029,