summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-06-21 20:48:58 +0200
committerBram Moolenaar <Bram@vim.org>2021-06-21 20:48:58 +0200
commit22f17a29cd0b0cc3107dc6cd1d96c62eee52a7d9 (patch)
treeb4f07018a9d2d00cea788c9f39dade141d9c3010
parentcb54bc65625abad9a0af501acac5c70fba17e2cc (diff)
patch 8.2.3031: no error if a function name starts with an underscorev8.2.3031
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)
-rw-r--r--src/testdir/test_vim9_func.vim18
-rw-r--r--src/userfunc.c3
-rw-r--r--src/version.c2
3 files changed, 22 insertions, 1 deletions
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 925e7c82a1..de09baaf6c 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -90,6 +90,24 @@ def Test_compile_error_in_called_function()
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
index 56b7df32f5..e2e745c338 100644
--- 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
index 0c3c887d13..77456bbbb9 100644
--- 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,