]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.0219: cannot make a funcref with "s:func" in a def function v9.0.0219
authorKota Kato <github@kat0h.com>
Tue, 16 Aug 2022 15:09:59 +0000 (16:09 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 16 Aug 2022 15:09:59 +0000 (16:09 +0100)
Problem:    Cannot make a funcref with "s:func" in a def function in legacy
            script.
Solution:   Allow for using a lower case function name after "s:". (Kota Kato,
            closes #10926)

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

index d67dd55b6ee2a9e23c7fa6364675e2ccf4b88f88..5c7545784f3d6d35c06e564ef85cadb9cf76351c 100644 (file)
@@ -1957,6 +1957,45 @@ def Test_call_funcref()
     g:listarg->assert_equal([1, 2, 3])
   END
   v9.CheckScriptSuccess(lines)
+
+  lines =<< trim END
+    function s:func(num)
+      return a:num * 2
+    endfunction
+
+    def s:CallFuncref()
+      var Funcref = function('s:func')
+      Funcref(3)->assert_equal(6)
+    enddef
+    call s:CallFuncref()
+  END
+  v9.CheckScriptSuccess(lines)
+
+  lines =<< trim END
+    function s:func(num)
+      return a:num * 2
+    endfunction
+
+    def s:CallFuncref()
+      var Funcref = function(s:func)
+      Funcref(3)->assert_equal(6)
+    enddef
+    call s:CallFuncref()
+  END
+  v9.CheckScriptSuccess(lines)
+
+  lines =<< trim END
+    function s:func(num)
+      return a:num * 2
+    endfunction
+
+    def s:CallFuncref()
+      var Funcref = s:func
+      Funcref(3)->assert_equal(6)
+    enddef
+    call s:CallFuncref()
+  END
+  v9.CheckScriptSuccess(lines)
 enddef
 
 let SomeFunc = function('len')
index ae3e20202b8a377c8ffa069f6a0ff4be9d810214..f612160fc872c3f209c7ffb1832456961745214b 100644 (file)
@@ -3995,7 +3995,8 @@ trans_function_name(
     {
        if (!vim9_local)
        {
-           if (vim9script && lead == 2 && !ASCII_ISUPPER(*lv.ll_name))
+           if (vim9script && lead == 2 && !ASCII_ISUPPER(*lv.ll_name)
+                                                  && current_script_is_vim9())
            {
                semsg(_(e_function_name_must_start_with_capital_str), start);
                goto theend;
index 5d9f9f77d0af7febff2cf7b2c7fc23947876fcba..3aff052a75beb4cfac89ef638c6e70aba1684c82 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    219,
 /**/
     218,
 /**/
index b2bb405f6fb9b6e389e8fdbb53fae3e94865130e..8cd095c1a796c1ea2ea9d8ee462316ab7cc656f3 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 /*
- * vim9cmds.c: Dealing with compiled function expressions
+ * vim9expr.c: Dealing with compiled function expressions
  */
 
 #define USING_FLOAT_STUFF
@@ -451,8 +451,7 @@ compile_load(
                              vim_free(name);
                              return FAIL;
                          }
-                         if (is_expr && ASCII_ISUPPER(*name)
-                                            && find_func(name, FALSE) != NULL)
+                         if (is_expr && find_func(name, FALSE) != NULL)
                              res = generate_funcref(cctx, name, FALSE);
                          else
                              res = compile_load_scriptvar(cctx, name,