]> granicus.if.org Git - vim/commitdiff
patch 8.2.3031: no error if a function name starts with an underscore v8.2.3031
authorBram Moolenaar <Bram@vim.org>
Mon, 21 Jun 2021 18:48:58 +0000 (20:48 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 21 Jun 2021 18:48:58 +0000 (20:48 +0200)
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)

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

index 925e7c82a1a23bf31e75956b90711a7df8c85a46..de09baaf6cd04a216989580c4f24dcabb06b406d 100644 (file)
@@ -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')
index 56b7df32f5310dac19e72cd332d13417d7cee53e..e2e745c338fa05a7803b05167cd0a07b17c53934 100644 (file)
@@ -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);
index 0c3c887d13fd202319c051287f3b50beb5eb7957..77456bbbb9bb4a4900cca50e8aa151c3f57fb094 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3031,
 /**/
     3030,
 /**/