]> granicus.if.org Git - vim/commitdiff
patch 8.2.3826: Vim9: using "g:Func" as funcref doesn't work in :def function v8.2.3826
authorBram Moolenaar <Bram@vim.org>
Thu, 16 Dec 2021 15:49:43 +0000 (15:49 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 16 Dec 2021 15:49:43 +0000 (15:49 +0000)
Problem:    Vim9: using "g:Func" as a funcref does not work in a :def
            function.
Solution:   Include "g:" in the function name. (closes #9336)

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

index 4cf37b76c0af597e2e5dbd91d425378c200392b0..76fd3fac1118d1565240c5083e4303dc87c3c271 100644 (file)
@@ -2413,7 +2413,7 @@ def Test_disassemble_dict_stack()
   assert_match('<SNR>\d*_UseMember\_s*' ..
           'var d = {func: Legacy}\_s*' ..
           '\d PUSHS "func"\_s*' ..
-          '\d PUSHFUNC "Legacy"\_s*' ..
+          '\d PUSHFUNC "g:Legacy"\_s*' ..
           '\d NEWDICT size 1\_s*' ..
           '\d STORE $0\_s*' ..
 
index 9dc0d738ded7f11d5a32483e55b0a0c109037633..f97f902f75c60121e1ec80eba5f0175dab04a95c 100644 (file)
@@ -1232,11 +1232,23 @@ def Test_set_opfunc_to_global_function()
       g:result = getreg('"')->count(' ')
       return ''
     enddef
+    # global function works at script level
     &operatorfunc = g:CountSpaces
     new
     'a b c d e'->setline(1)
     feedkeys("g@_", 'x')
     assert_equal(4, g:result)
+
+    &operatorfunc = ''
+    g:result = 0
+    # global function works in :def function
+    def Func()
+      &operatorfunc = g:CountSpaces
+    enddef
+    Func()
+    feedkeys("g@_", 'x')
+    assert_equal(4, g:result)
+
     bwipe!
   END
   CheckScriptSuccess(lines)
index d1b667a5063c6d005016633c6d69bc98b36f48be..633ebf026e1d5f026ac2685e8f062aa63d4b24f7 100644 (file)
@@ -749,6 +749,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3826,
 /**/
     3825,
 /**/
index a75219e0a2fec68d9921b82189198d2c09a0b9dd..50dc7560521b405ced9a7c78e1ffe5575ed88ccf 100644 (file)
@@ -1281,12 +1281,26 @@ generate_PUSHBLOB(cctx_T *cctx, blob_T *blob)
 generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type)
 {
     isn_T      *isn;
+    char_u     *funcname;
 
     RETURN_OK_IF_SKIP(cctx);
     if ((isn = generate_instr_type(cctx, ISN_PUSHFUNC, type)) == NULL)
        return FAIL;
-    isn->isn_arg.string = name == NULL ? NULL : vim_strsave(name);
+    if (name == NULL)
+       funcname = NULL;
+    else if (*name == K_SPECIAL)  // script-local
+       funcname = vim_strsave(name);
+    else
+    {
+       funcname = alloc(STRLEN(name) + 3);
+       if (funcname != NULL)
+       {
+           STRCPY(funcname, "g:");
+           STRCPY(funcname + 2, name);
+       }
+    }
 
+    isn->isn_arg.string = funcname;
     return OK;
 }