diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-02-07 20:30:57 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-02-07 20:30:57 +0000 |
commit | f681cfb90b972cb347b3d707c87e48f8accd0e2a (patch) | |
tree | dec6119e3cede17c28e604dbabfc01ebfc491803 | |
parent | 7aca5ca6763e50d2c23953b20e30fca7457c9abf (diff) |
patch 8.2.4323: Vim9: nested function name can start with "_"v8.2.4323
Problem: Vim9: nested function name can start with "_".
Solution: Use same rule for function name for nested functions.
(closes #9713)
-rw-r--r-- | src/testdir/test_vim9_func.vim | 28 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9compile.c | 5 |
3 files changed, 33 insertions, 2 deletions
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim index 4ac4643e07..86b0763dcc 100644 --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -679,6 +679,30 @@ def Test_nested_function() assert_equal('ok', g:result) unlet g:result + lines =<< trim END + vim9script + def Outer() + def _Inner() + echo 'bad' + enddef + Inner() + enddef + defcompile + END + v9.CheckScriptFailure(lines, 'E128:') + + lines =<< trim END + vim9script + def Outer() + def g:inner() + echo 'bad' + enddef + Inner() + enddef + defcompile + END + v9.CheckScriptFailure(lines, 'E128:') + # nested function inside conditional lines =<< trim END vim9script @@ -3135,11 +3159,11 @@ func Test_partial_call_fails() def Iter(container: any): any var idx = -1 var obj = {state: container} - def g:__NextItem__(self: dict<any>): any + def g:NextItem__(self: dict<any>): any ++idx return self.state[idx] enddef - obj.__next__ = function('g:__NextItem__', [obj]) + obj.__next__ = function('g:NextItem__', [obj]) return obj enddef diff --git a/src/version.c b/src/version.c index c1f90cdd03..2d0bb2d6c0 100644 --- a/src/version.c +++ b/src/version.c @@ -747,6 +747,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4323, +/**/ 4322, /**/ 4321, diff --git a/src/vim9compile.c b/src/vim9compile.c index d0479a5fbd..080a53c693 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -886,6 +886,11 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx, garray_T *lines_to_free) } if (check_defined(name_start, name_end - name_start, cctx, FALSE) == FAIL) return NULL; + if (!ASCII_ISUPPER(is_global ? name_start[2] : name_start[0])) + { + semsg(_(e_function_name_must_start_with_capital_or_s_str), name_start); + return NULL; + } eap->arg = name_end; fill_exarg_from_cctx(eap, cctx); |