• R/O
  • SSH

vim: コミット

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


コミットメタ情報

リビジョンfacb54d20a504b13b2134b0de9facf1f101bf1f3 (tree)
日時2022-01-19 02:45:02
作者Bram Moolenaar <Bram@vim....>
コミッターBram Moolenaar

ログメッセージ

patch 8.2.4137: Vim9: calling import with and without method is inconsistent

Commit: https://github.com/vim/vim/commit/d02dce2bb572f0e6b4570442e9cdbed14ef41820
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jan 18 17:43:04 2022 +0000

patch 8.2.4137: Vim9: calling import with and without method is inconsistent
Problem: Vim9: calling import with and without method is inconsistent.
Solution: Set a flag that a parenthsis follows to compile_load_scriptvar().
Add some more tests. Improve error message.

変更サマリ

差分

diff -r da41f5bae90e -r facb54d20a50 src/testdir/test_vim9_import.vim
--- a/src/testdir/test_vim9_import.vim Tue Jan 18 17:30:05 2022 +0100
+++ b/src/testdir/test_vim9_import.vim Tue Jan 18 18:45:02 2022 +0100
@@ -1256,6 +1256,136 @@
12561256 &rtp = save_rtp
12571257 enddef
12581258
1259+def Test_import_autoload_not_exported()
1260+ mkdir('Xdir/autoload', 'p')
1261+ var save_rtp = &rtp
1262+ exe 'set rtp^=' .. getcwd() .. '/Xdir'
1263+
1264+ # error when using an item that is not exported from an autoload script
1265+ var exportLines =<< trim END
1266+ vim9script
1267+ var notExported = 123
1268+ def NotExport()
1269+ echo 'nop'
1270+ enddef
1271+ END
1272+ writefile(exportLines, 'Xdir/autoload/notExport1.vim')
1273+
1274+ var lines =<< trim END
1275+ vim9script
1276+ import autoload 'notExport1.vim'
1277+ echo notExport1.notFound
1278+ END
1279+ CheckScriptFailure(lines, 'E1048: Item not found in script: notFound')
1280+
1281+ lines =<< trim END
1282+ vim9script
1283+ import autoload 'notExport1.vim'
1284+ echo notExport1.notExported
1285+ END
1286+ CheckScriptFailure(lines, 'E1049: Item not exported in script: notExported')
1287+
1288+ lines =<< trim END
1289+ vim9script
1290+ import autoload 'notExport1.vim'
1291+ echo notExport1.NotFunc()
1292+ END
1293+ CheckScriptFailure(lines, 'E1048: Item not found in script: NotFunc')
1294+
1295+ lines =<< trim END
1296+ vim9script
1297+ import autoload 'notExport1.vim'
1298+ echo notExport1.NotExport()
1299+ END
1300+ CheckScriptFailure(lines, 'E1049: Item not exported in script: NotExport')
1301+
1302+ lines =<< trim END
1303+ vim9script
1304+ import autoload 'notExport1.vim'
1305+ echo 'text'->notExport1.NotFunc()
1306+ END
1307+ CheckScriptFailure(lines, 'E1048: Item not found in script: NotFunc')
1308+
1309+ lines =<< trim END
1310+ vim9script
1311+ import autoload 'notExport1.vim'
1312+ echo 'text'->notExport1.NotExport()
1313+ END
1314+ CheckScriptFailure(lines, 'E1049: Item not exported in script: NotExport')
1315+
1316+ # using a :def function we use a different autoload script every time so that
1317+ # the function is compiled without the script loaded
1318+ writefile(exportLines, 'Xdir/autoload/notExport2.vim')
1319+ lines =<< trim END
1320+ vim9script
1321+ import autoload 'notExport2.vim'
1322+ def Testit()
1323+ echo notExport2.notFound
1324+ enddef
1325+ Testit()
1326+ END
1327+ CheckScriptFailure(lines, 'E1048: Item not found in script: notExport2#notFound')
1328+
1329+ writefile(exportLines, 'Xdir/autoload/notExport3.vim')
1330+ lines =<< trim END
1331+ vim9script
1332+ import autoload 'notExport3.vim'
1333+ def Testit()
1334+ echo notExport3.notExported
1335+ enddef
1336+ Testit()
1337+ END
1338+ # don't get E1049 because it is too complicated to figure out
1339+ CheckScriptFailure(lines, 'E1048: Item not found in script: notExport3#notExported')
1340+
1341+ writefile(exportLines, 'Xdir/autoload/notExport4.vim')
1342+ lines =<< trim END
1343+ vim9script
1344+ import autoload 'notExport4.vim'
1345+ def Testit()
1346+ echo notExport4.NotFunc()
1347+ enddef
1348+ Testit()
1349+ END
1350+ CheckScriptFailure(lines, 'E117: Unknown function: notExport4#NotFunc')
1351+
1352+ writefile(exportLines, 'Xdir/autoload/notExport5.vim')
1353+ lines =<< trim END
1354+ vim9script
1355+ import autoload 'notExport5.vim'
1356+ def Testit()
1357+ echo notExport5.NotExport()
1358+ enddef
1359+ Testit()
1360+ END
1361+ CheckScriptFailure(lines, 'E117: Unknown function: notExport5#NotExport')
1362+
1363+ writefile(exportLines, 'Xdir/autoload/notExport6.vim')
1364+ lines =<< trim END
1365+ vim9script
1366+ import autoload 'notExport6.vim'
1367+ def Testit()
1368+ echo 'text'->notExport6.NotFunc()
1369+ enddef
1370+ Testit()
1371+ END
1372+ CheckScriptFailure(lines, 'E117: Unknown function: notExport6#NotFunc')
1373+
1374+ writefile(exportLines, 'Xdir/autoload/notExport7.vim')
1375+ lines =<< trim END
1376+ vim9script
1377+ import autoload 'notExport7.vim'
1378+ def Testit()
1379+ echo 'text'->notExport7.NotExport()
1380+ enddef
1381+ Testit()
1382+ END
1383+ CheckScriptFailure(lines, 'E117: Unknown function: notExport7#NotExport')
1384+
1385+ delete('Xdir', 'rf')
1386+ &rtp = save_rtp
1387+enddef
1388+
12591389 def Test_vim9script_autoload_call()
12601390 mkdir('Xdir/autoload', 'p')
12611391 var save_rtp = &rtp
diff -r da41f5bae90e -r facb54d20a50 src/version.c
--- a/src/version.c Tue Jan 18 17:30:05 2022 +0100
+++ b/src/version.c Tue Jan 18 18:45:02 2022 +0100
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 4137,
755+/**/
754756 4136,
755757 /**/
756758 4135,
diff -r da41f5bae90e -r facb54d20a50 src/vim9execute.c
--- a/src/vim9execute.c Tue Jan 18 17:30:05 2022 +0100
+++ b/src/vim9execute.c Tue Jan 18 18:45:02 2022 +0100
@@ -2240,33 +2240,19 @@
22402240 iptr->isn_arg.string, TRUE);
22412241 if (did_emsg)
22422242 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- }
22642243 }
22652244
22662245 if (di == NULL)
22672246 {
22682247 SOURCING_LNUM = iptr->isn_lnum;
2269- semsg(_(e_undefined_variable_char_str),
2248+ if (vim_strchr(iptr->isn_arg.string,
2249+ AUTOLOAD_CHAR) != NULL)
2250+ // no check if the item exists in the script but
2251+ // isn't exported, it is too complicated
2252+ semsg(_(e_item_not_found_in_script_str),
2253+ iptr->isn_arg.string);
2254+ else
2255+ semsg(_(e_undefined_variable_char_str),
22702256 namespace, iptr->isn_arg.string);
22712257 goto on_error;
22722258 }
diff -r da41f5bae90e -r facb54d20a50 src/vim9expr.c
--- a/src/vim9expr.c Tue Jan 18 17:30:05 2022 +0100
+++ b/src/vim9expr.c Tue Jan 18 18:45:02 2022 +0100
@@ -21,6 +21,9 @@
2121 # include "vim9.h"
2222 #endif
2323
24+// flag passed from compile_subscript() to compile_load_scriptvar()
25+static int paren_follows_after_expr = 0;
26+
2427 /*
2528 * Generate code for any ppconst entries.
2629 */
@@ -277,7 +280,6 @@
277280 int done = FALSE;
278281 int res = OK;
279282
280- // TODO: if this is an autoload import do something else.
281283 // Need to lookup the member.
282284 if (*p != '.')
283285 {
@@ -306,7 +308,7 @@
306308
307309 // autoload script must be loaded later, access by the autoload
308310 // name.
309- if (cc == '(')
311+ if (cc == '(' || paren_follows_after_expr)
310312 res = generate_PUSHFUNC(cctx, auto_name, &t_func_any);
311313 else
312314 res = generate_LOAD(cctx, ISN_LOADG, 0, auto_name, &t_any);
@@ -1736,12 +1738,19 @@
17361738 int save_len = cctx->ctx_ufunc->uf_lines.ga_len;
17371739
17381740 *paren = NUL;
1741+
1742+ // instead of using LOADG for "import.Func" use PUSHFUNC
1743+ ++paren_follows_after_expr;
1744+
17391745 // do not look in the next line
17401746 cctx->ctx_ufunc->uf_lines.ga_len = 1;
1747+
17411748 fail = compile_expr8(arg, cctx, ppconst) == FAIL
17421749 || *skipwhite(*arg) != NUL;
17431750 *paren = '(';
1751+ --paren_follows_after_expr;
17441752 cctx->ctx_ufunc->uf_lines.ga_len = save_len;
1753+
17451754 if (fail)
17461755 {
17471756 semsg(_(e_invalid_expression_str), pstart);
diff -r da41f5bae90e -r facb54d20a50 src/vim9script.c
--- a/src/vim9script.c Tue Jan 18 17:30:05 2022 +0100
+++ b/src/vim9script.c Tue Jan 18 18:45:02 2022 +0100
@@ -707,22 +707,36 @@
707707 sprintf((char *)funcname + 3, "%ld_%s", (long)sid, name);
708708 }
709709 *ufunc = find_func(funcname, FALSE);
710- if (funcname != buffer)
711- vim_free(funcname);
712710
713711 if (*ufunc == NULL)
714712 {
715713 if (verbose)
716- semsg(_(e_item_not_found_in_script_str), name);
717- return -1;
714+ {
715+ ufunc_T *alt_ufunc = NULL;
716+
717+ if (script->sn_autoload_prefix != NULL)
718+ {
719+ // try find the function by the script-local name
720+ funcname[0] = K_SPECIAL;
721+ funcname[1] = KS_EXTRA;
722+ funcname[2] = (int)KE_SNR;
723+ sprintf((char *)funcname + 3, "%ld_%s", (long)sid, name);
724+ alt_ufunc = find_func(funcname, FALSE);
725+ }
726+ if (alt_ufunc != NULL)
727+ semsg(_(e_item_not_exported_in_script_str), name);
728+ else
729+ semsg(_(e_item_not_found_in_script_str), name);
730+ }
718731 }
719732 else if (((*ufunc)->uf_flags & FC_EXPORT) == 0)
720733 {
721734 if (verbose)
722735 semsg(_(e_item_not_exported_in_script_str), name);
723736 *ufunc = NULL;
724- return -1;
725737 }
738+ if (funcname != buffer)
739+ vim_free(funcname);
726740 }
727741
728742 return idx;
旧リポジトリブラウザで表示