patch 8.2.4323: Vim9: nested function name can start with "_" v8.2.4323
authorBram Moolenaar <Bram@vim.org>
Mon, 7 Feb 2022 20:30:57 +0000 (20:30 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 7 Feb 2022 20:30:57 +0000 (20:30 +0000)
Problem:    Vim9: nested function name can start with "_".
Solution:   Use same rule for function name for nested functions.
            (closes #9713)

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

index 4ac4643e073a2bf9141aac1f142f5e8ebd358f64..86b0763dcc8b347cdb5d6ec6248ca94d112d62db 100644 (file)
@@ -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
 
index c1f90cdd037d72d59f059c3a2ce842a532080ce2..2d0bb2d6c00acbbf1aea6e92c23ea9dc39adca20 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4323,
 /**/
     4322,
 /**/
index d0479a5fbd9ec2bcad27156b99e7375d19a9b083..080a53c6931d6645d8375cd4e7964577cc02d8f8 100644 (file)
@@ -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);