• R/O
  • SSH

vim: コミット

Mirror of the Vim source from https://github.com/vim/vim


コミットメタ情報

リビジョン6c177a9b436e55caca448bdd9b12e8430fc28de4 (tree)
日時2022-01-18 22:00:05
作者Bram Moolenaar <Bram@vim....>
コミッターBram Moolenaar

ログメッセージ

patch 8.2.4131: Vim9: calling function in autoload import does not work

Commit: https://github.com/vim/vim/commit/cbbc48f64b9cfd88720dc94b0578a3726f725178
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jan 18 12:58:28 2022 +0000

patch 8.2.4131: Vim9: calling function in autoload import does not work
Problem: Vim9: calling function in autoload import does not work in a :def
function.
Solution: When a variable is not found and a PCALL follows use a funcref.
(closes #9550)

変更サマリ

差分

diff -r 93806718f805 -r 6c177a9b436e src/testdir/test_vim9_import.vim
--- a/src/testdir/test_vim9_import.vim Tue Jan 18 12:45:05 2022 +0100
+++ b/src/testdir/test_vim9_import.vim Tue Jan 18 14:00:05 2022 +0100
@@ -1264,6 +1264,10 @@
12641264 var lines =<< trim END
12651265 vim9script autoload
12661266
1267+ export def RetArg(arg: string): string
1268+ return arg
1269+ enddef
1270+
12671271 export def Getother()
12681272 g:result = 'other'
12691273 enddef
@@ -1273,6 +1277,13 @@
12731277 lines =<< trim END
12741278 vim9script
12751279 import autoload 'another.vim'
1280+
1281+ # compile this before 'another.vim' is loaded
1282+ def CallAnother()
1283+ assert_equal('foo', 'foo'->another.RetArg())
1284+ enddef
1285+ CallAnother()
1286+
12761287 call another.Getother()
12771288 assert_equal('other', g:result)
12781289 END
diff -r 93806718f805 -r 6c177a9b436e src/version.c
--- a/src/version.c Tue Jan 18 12:45:05 2022 +0100
+++ b/src/version.c Tue Jan 18 14:00:05 2022 +0100
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 4131,
755+/**/
754756 4130,
755757 /**/
756758 4129,
diff -r 93806718f805 -r 6c177a9b436e src/vim9execute.c
--- a/src/vim9execute.c Tue Jan 18 12:45:05 2022 +0100
+++ b/src/vim9execute.c Tue Jan 18 14:00:05 2022 +0100
@@ -2200,10 +2200,12 @@
22002200 case ISN_LOADW:
22012201 case ISN_LOADT:
22022202 {
2203- dictitem_T *di = NULL;
2204- hashtab_T *ht = NULL;
2205- char namespace;
2206-
2203+ dictitem_T *di = NULL;
2204+ hashtab_T *ht = NULL;
2205+ char namespace;
2206+
2207+ if (GA_GROW_FAILS(&ectx->ec_stack, 1))
2208+ goto theend;
22072209 switch (iptr->isn_type)
22082210 {
22092211 case ISN_LOADG:
@@ -2227,14 +2229,38 @@
22272229 }
22282230 di = find_var_in_ht(ht, 0, iptr->isn_arg.string, TRUE);
22292231
2230- if (di == NULL && ht == get_globvar_ht())
2232+ if (di == NULL && ht == get_globvar_ht()
2233+ && vim_strchr(iptr->isn_arg.string,
2234+ AUTOLOAD_CHAR) != NULL)
22312235 {
2232- // may need to load autoload script
2236+ // Global variable has an autoload name, may still need
2237+ // to load the script.
22332238 if (script_autoload(iptr->isn_arg.string, FALSE))
22342239 di = find_var_in_ht(ht, 0,
22352240 iptr->isn_arg.string, TRUE);
22362241 if (did_emsg)
22372242 goto on_error;
2243+ if (di == NULL)
2244+ {
2245+ isn_T *next = &ectx->ec_instr[ectx->ec_iidx];
2246+
2247+ // When compiling "script.Func()" when "script" is
2248+ // an autoload import then this results in
2249+ // "LOADG script#Func" because we don't know if it
2250+ // is a funcref variable or a function name. In
2251+ // that case a PCALL follows, push the function
2252+ // name instead.
2253+ if (next->isn_type == ISN_PCALL)
2254+ {
2255+ tv = STACK_TV_BOT(0);
2256+ tv->v_type = VAR_FUNC;
2257+ tv->v_lock = 0;
2258+ tv->vval.v_string =
2259+ vim_strsave(iptr->isn_arg.string);
2260+ ++ectx->ec_stack.ga_len;
2261+ break;
2262+ }
2263+ }
22382264 }
22392265
22402266 if (di == NULL)
@@ -2246,8 +2272,6 @@
22462272 }
22472273 else
22482274 {
2249- if (GA_GROW_FAILS(&ectx->ec_stack, 1))
2250- goto theend;
22512275 copy_tv(&di->di_tv, STACK_TV_BOT(0));
22522276 ++ectx->ec_stack.ga_len;
22532277 }
旧リポジトリブラウザで表示