]> granicus.if.org Git - vim/commitdiff
patch 8.2.4067: Vim9: cannot call imported function with :call v8.2.4067
authorBram Moolenaar <Bram@vim.org>
Wed, 12 Jan 2022 12:48:17 +0000 (12:48 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 12 Jan 2022 12:48:17 +0000 (12:48 +0000)
Problem:    Vim9: cannot call imported function with :call. (Drew Vogel)
Solution:   Translate the function name. (closes #9510)

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

index 7aa1549155fdd3dbfad77873d92f3544a023089f..d43012c84f8ebbb56d31757dcbd2b4a31d716054 100644 (file)
@@ -1185,6 +1185,35 @@ def Test_vim9script_autoload()
   END
   CheckScriptSuccess(lines)
 
+  unlet g:prefixed_loaded
+  unlet g:expected_loaded
+  delete('Xdir', 'rf')
+  &rtp = save_rtp
+enddef
+
+def Test_vim9script_autoload_call()
+  mkdir('Xdir/autoload', 'p')
+  var save_rtp = &rtp
+  exe 'set rtp^=' .. getcwd() .. '/Xdir'
+
+  var lines =<< trim END
+     vim9script autoload
+
+     export def Getother()
+       g:result = 'other'
+     enddef
+  END
+  writefile(lines, 'Xdir/autoload/other.vim')
+
+  lines =<< trim END
+      vim9script
+      import autoload 'other.vim'
+      call other.Getother()
+      assert_equal('other', g:result)
+  END
+  CheckScriptSuccess(lines)
+
+  unlet g:result
   delete('Xdir', 'rf')
   &rtp = save_rtp
 enddef
index 4516a48aab8f088fee9a09de0adb2a89542afd15..a227700dc02578234be06ffa2bc725298003dc2d 100644 (file)
@@ -3744,6 +3744,30 @@ trans_function_name(
        if (name == lv.ll_exp_name)
            name = NULL;
     }
+    else if (lv.ll_sid > 0)
+    {
+       scriptitem_T    *si = SCRIPT_ITEM(lv.ll_sid);
+       int             cc = *lv.ll_name_end;
+
+       // function in another script.  Prefix <SNR>99_ or the autoload prefix.
+       *lv.ll_name_end = NUL;
+       if (si->sn_autoload_prefix != NULL)
+       {
+           name = concat_str(si->sn_autoload_prefix, lv.ll_name);
+       }
+       else
+       {
+           sid_buf[0] = K_SPECIAL;
+           sid_buf[1] = KS_EXTRA;
+           sid_buf[2] = (int)KE_SNR;
+           vim_snprintf((char *)sid_buf + 3, sizeof(sid_buf) - 3,
+                                           "%ld_", (long)current_sctx.sc_sid);
+           name = concat_str(sid_buf, lv.ll_name);
+       }
+       *lv.ll_name_end = cc;
+       *pp = end;
+       goto theend;
+    }
     else if (!(flags & TFN_NO_DEREF))
     {
        len = (int)(end - *pp);
index 24d2f087d3cff715312bffee2714d32427f2577f..adf217566d9c0d170ed938816e8d30499efa5e0e 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4067,
 /**/
     4066,
 /**/