]> granicus.if.org Git - vim/commitdiff
patch 8.2.1351: Vim9: no proper error if using namespace for nested function v8.2.1351
authorBram Moolenaar <Bram@vim.org>
Sat, 1 Aug 2020 20:35:13 +0000 (22:35 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 1 Aug 2020 20:35:13 +0000 (22:35 +0200)
Problem:    Vim9: no proper error if using namespace for nested function.
Solution:   Specifically check for a namespace. (closes #6582)

src/testdir/test_vim9_func.vim
src/version.c
src/vim9compile.c

index 85fd8ff4e0acd527d9c70004d41e290fb07ff699..1ccaeb308a1385003578d7ee5b90f7435786b3e1 100644 (file)
@@ -131,6 +131,8 @@ def Test_nested_function()
   CheckDefFailure(['def Nested(arg: string)', 'enddef', 'Nested()'], 'E119:')
 
   CheckDefFailure(['func Nested()', 'endfunc'], 'E1086:')
+  CheckDefFailure(['def s:Nested()', 'enddef'], 'E1075:')
+  CheckDefFailure(['def b:Nested()', 'enddef'], 'E1075:')
 enddef
 
 func Test_call_default_args_from_func()
index 00d8c2dab6a6c79550367ccc1c85e6415f96831f..f032581c0cdd1e672afa8ffc619a5e8ac5fdb42d 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1351,
 /**/
     1350,
 /**/
index 6581708bc9636b7879314b270572fa083f1ee1d2..61be54d7b726d919f63898ccfcf91724a720da34 100644 (file)
@@ -4899,12 +4899,18 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx)
 {
     int                is_global = *eap->arg == 'g' && eap->arg[1] == ':';
     char_u     *name_start = eap->arg;
-    char_u     *name_end = to_name_end(eap->arg, is_global);
+    char_u     *name_end = to_name_end(eap->arg, TRUE);
     char_u     *lambda_name;
     lvar_T     *lvar;
     ufunc_T    *ufunc;
     int                r;
 
+    // Only g:Func() can use a namespace.
+    if (name_start[1] == ':' && !is_global)
+    {
+       semsg(_(e_namespace), name_start);
+       return NULL;
+    }
     if (check_defined(name_start, name_end - name_start, cctx) == FAIL)
        return NULL;