• R/O
  • SSH

vim: コミット

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


コミットメタ情報

リビジョン63f8dbcf6a749f1f189bf19f355ae2acbc595412 (tree)
日時2022-01-18 06:00:03
作者Bram Moolenaar <Bram@vim....>
コミッターBram Moolenaar

ログメッセージ

patch 8.2.4124: Vim9: method in compiled function may not see script item

Commit: https://github.com/vim/vim/commit/6389baa6691fde4ca56ec6243ed83322543df300
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jan 17 20:50:40 2022 +0000

patch 8.2.4124: Vim9: method in compiled function may not see script item
Problem: Vim9: method in compiled function may not see script item.
Solution: Make sure not to skip to the next line. (closes https://github.com/vim/vim/issues/9496)

変更サマリ

差分

diff -r 19849ccc38a0 -r 63f8dbcf6a74 src/testdir/test_vim9_expr.vim
--- a/src/testdir/test_vim9_expr.vim Mon Jan 17 21:15:03 2022 +0100
+++ b/src/testdir/test_vim9_expr.vim Mon Jan 17 22:00:03 2022 +0100
@@ -1717,7 +1717,7 @@
17171717 let $TESTVAR = 'testvar'
17181718
17191719 " type casts
1720-def Test_expr7t()
1720+def Test_expr7()
17211721 var lines =<< trim END
17221722 var ls: list<string> = ['a', <string>g:string_empty]
17231723 var ln: list<number> = [<number>g:anint, <number>g:thefour]
@@ -1743,7 +1743,7 @@
17431743 enddef
17441744
17451745 " test low level expression
1746-def Test_expr7_number()
1746+def Test_expr8_number()
17471747 # number constant
17481748 var lines =<< trim END
17491749 assert_equal(0, 0)
@@ -1756,7 +1756,7 @@
17561756 CheckDefAndScriptSuccess(lines)
17571757 enddef
17581758
1759-def Test_expr7_float()
1759+def Test_expr8_float()
17601760 # float constant
17611761 if !has('float')
17621762 MissingFeature 'float'
@@ -1771,7 +1771,7 @@
17711771 endif
17721772 enddef
17731773
1774-def Test_expr7_blob()
1774+def Test_expr8_blob()
17751775 # blob constant
17761776 var lines =<< trim END
17771777 assert_equal(g:blob_empty, 0z)
@@ -1803,7 +1803,7 @@
18031803 CheckDefAndScriptFailure(["var x = 0z123"], 'E973:', 1)
18041804 enddef
18051805
1806-def Test_expr7_string()
1806+def Test_expr8_string()
18071807 # string constant
18081808 var lines =<< trim END
18091809 assert_equal(g:string_empty, '')
@@ -1820,7 +1820,7 @@
18201820 CheckDefAndScriptFailure(["var x = 'abc"], 'E115:', 1)
18211821 enddef
18221822
1823-def Test_expr7_vimvar()
1823+def Test_expr8_vimvar()
18241824 v:errors = []
18251825 var errs: list<string> = v:errors
18261826 CheckDefFailure(['var errs: list<number> = v:errors'], 'E1012:')
@@ -1845,7 +1845,7 @@
18451845 bwipe!
18461846 enddef
18471847
1848-def Test_expr7_special()
1848+def Test_expr8_special()
18491849 # special constant
18501850 var lines =<< trim END
18511851 assert_equal(g:special_true, true)
@@ -1882,7 +1882,7 @@
18821882 CheckDefAndScriptFailure(['v:none = 22'], 'E46:', 1)
18831883 enddef
18841884
1885-def Test_expr7_list()
1885+def Test_expr8_list()
18861886 # list
18871887 var lines =<< trim END
18881888 assert_equal(g:list_empty, [])
@@ -1955,7 +1955,7 @@
19551955 CheckDefAndScriptFailure(lines + ['echo numbers[a :b]'], 'E1004:', 4)
19561956 enddef
19571957
1958-def Test_expr7_list_vim9script()
1958+def Test_expr8_list_vim9script()
19591959 var lines =<< trim END
19601960 var l = [
19611961 11,
@@ -2043,7 +2043,7 @@
20432043 x == 2
20442044 enddef
20452045
2046-def Test_expr7_lambda()
2046+def Test_expr8_lambda()
20472047 var lines =<< trim END
20482048 var La = () => 'result'
20492049 # comment
@@ -2129,7 +2129,7 @@
21292129 CheckDefAndScriptSuccess(lines)
21302130 enddef
21312131
2132-def Test_expr7_lambda_block()
2132+def Test_expr8_lambda_block()
21332133 var lines =<< trim END
21342134 var Func = (s: string): string => {
21352135 return 'hello ' .. s
@@ -2209,7 +2209,7 @@
22092209 x == 2
22102210 enddef
22112211
2212-def Test_expr7_new_lambda()
2212+def Test_expr8_new_lambda()
22132213 var lines =<< trim END
22142214 var La = () => 'result'
22152215 assert_equal('result', La())
@@ -2294,7 +2294,7 @@
22942294 CheckDefAndScriptFailure(['var Fx = (a) => [0', ' 1]'], 'E696:', 2)
22952295 enddef
22962296
2297-def Test_expr7_lambda_vim9script()
2297+def Test_expr8_lambda_vim9script()
22982298 var lines =<< trim END
22992299 var v = 10->((a) =>
23002300 a
@@ -2313,7 +2313,7 @@
23132313 CheckDefAndScriptSuccess(lines)
23142314 enddef
23152315
2316-def Test_expr7_funcref()
2316+def Test_expr8_funcref()
23172317 var lines =<< trim END
23182318 def RetNumber(): number
23192319 return 123
@@ -2350,7 +2350,7 @@
23502350 let g:test_space_dict = {'': 'empty', ' ': 'space'}
23512351 let g:test_hash_dict = #{one: 1, two: 2}
23522352
2353-def Test_expr7_dict()
2353+def Test_expr8_dict()
23542354 # dictionary
23552355 var lines =<< trim END
23562356 assert_equal(g:dict_empty, {})
@@ -2461,7 +2461,7 @@
24612461 CheckDefExecAndScriptFailure(['{}[getftype("file")]'], 'E716: Key not present in Dictionary: ""', 1)
24622462 enddef
24632463
2464-def Test_expr7_dict_vim9script()
2464+def Test_expr8_dict_vim9script()
24652465 var lines =<< trim END
24662466 var d = {
24672467 ['one']:
@@ -2592,7 +2592,7 @@
25922592 CheckScriptSuccess(lines)
25932593 enddef
25942594
2595-def Test_expr7_dict_in_block()
2595+def Test_expr8_dict_in_block()
25962596 var lines =<< trim END
25972597 vim9script
25982598 command MyCommand {
@@ -2615,7 +2615,7 @@
26152615 delcommand YourCommand
26162616 enddef
26172617
2618-def Test_expr7_call_2bool()
2618+def Test_expr8_call_2bool()
26192619 var lines =<< trim END
26202620 vim9script
26212621
@@ -2663,7 +2663,7 @@
26632663 CheckDefExecAndScriptFailure(["var d: dict<number>", "d = g:list_empty"], 'E1012: Type mismatch; expected dict<number> but got list<unknown>', 2)
26642664 enddef
26652665
2666-def Test_expr7_any_index_slice()
2666+def Test_expr8_any_index_slice()
26672667 var lines =<< trim END
26682668 # getting the one member should clear the list only after getting the item
26692669 assert_equal('bbb', ['aaa', 'bbb', 'ccc'][1])
@@ -2817,7 +2817,7 @@
28172817 b:someVar = &fdm
28182818 enddef
28192819
2820-def Test_expr7_option()
2820+def Test_expr8_option()
28212821 var lines =<< trim END
28222822 # option
28232823 set ts=11
@@ -2844,7 +2844,7 @@
28442844 CheckDefAndScriptSuccess(lines)
28452845 enddef
28462846
2847-def Test_expr7_environment()
2847+def Test_expr8_environment()
28482848 var lines =<< trim END
28492849 # environment variable
28502850 assert_equal('testvar', $TESTVAR)
@@ -2856,7 +2856,7 @@
28562856 CheckDefAndScriptFailure(["$"], ['E1002:', 'E15:'], 1)
28572857 enddef
28582858
2859-def Test_expr7_register()
2859+def Test_expr8_register()
28602860 var lines =<< trim END
28612861 @a = 'register a'
28622862 assert_equal('register a', @a)
@@ -2882,7 +2882,7 @@
28822882 enddef
28832883
28842884 " This is slow when run under valgrind.
2885-def Test_expr7_namespace()
2885+def Test_expr8_namespace()
28862886 var lines =<< trim END
28872887 g:some_var = 'some'
28882888 assert_equal('some', get(g:, 'some_var'))
@@ -2911,7 +2911,7 @@
29112911 CheckDefAndScriptSuccess(lines)
29122912 enddef
29132913
2914-def Test_expr7_namespace_loop_def()
2914+def Test_expr8_namespace_loop_def()
29152915 var lines =<< trim END
29162916 # check using g: in a for loop more than DO_NOT_FREE_CNT times
29172917 var exists = 0
@@ -2930,8 +2930,8 @@
29302930 enddef
29312931
29322932 " NOTE: this is known to be slow. To skip use:
2933-" :let $TEST_SKIP_PAT = 'Test_expr7_namespace_loop_script'
2934-def Test_expr7_namespace_loop_script()
2933+" :let $TEST_SKIP_PAT = 'Test_expr8_namespace_loop_script'
2934+def Test_expr8_namespace_loop_script()
29352935 var lines =<< trim END
29362936 vim9script
29372937 # check using g: in a for loop more than DO_NOT_FREE_CNT times
@@ -2950,7 +2950,7 @@
29502950 CheckScriptSuccess(lines)
29512951 enddef
29522952
2953-def Test_expr7_parens()
2953+def Test_expr8_parens()
29542954 # (expr)
29552955 var lines =<< trim END
29562956 assert_equal(4, (6 * 4) / 6)
@@ -2982,7 +2982,7 @@
29822982 CheckDefAndScriptSuccess(lines)
29832983 enddef
29842984
2985-def Test_expr7_negate_add()
2985+def Test_expr8_negate_add()
29862986 var lines =<< trim END
29872987 assert_equal(-99, -99)
29882988 assert_equal(-99, - 99)
@@ -3031,7 +3031,7 @@
30313031 legacy return #{key: 'ok'}.key
30323032 enddef
30333033
3034-def Test_expr7_legacy_script()
3034+def Test_expr8_legacy_script()
30353035 var lines =<< trim END
30363036 let s:legacy = 'legacy'
30373037 def GetLocal(): string
@@ -3065,7 +3065,7 @@
30653065 return arg
30663066 enddef
30673067
3068-def Test_expr7_call()
3068+def Test_expr8_call()
30693069 var lines =<< trim END
30703070 assert_equal('yes', 'yes'->Echo())
30713071 assert_equal(true, !range(5)->empty())
@@ -3098,7 +3098,7 @@
30983098 delete('Xruntime', 'rf')
30993099 enddef
31003100
3101-def Test_expr7_method_call()
3101+def Test_expr8_method_call()
31023102 var lines =<< trim END
31033103 new
31043104 setline(1, ['first', 'last'])
@@ -3175,7 +3175,7 @@
31753175 CheckDefExecFailure(lines, 'E1013:')
31763176 enddef
31773177
3178-def Test_expr7_method_call_linebreak()
3178+def Test_expr8_method_call_linebreak()
31793179 # this was giving an error when skipping over the expression
31803180 var lines =<< trim END
31813181 vim9script
@@ -3191,8 +3191,34 @@
31913191 CheckScriptSuccess(lines)
31923192 enddef
31933193
3194-
3195-def Test_expr7_not()
3194+def Test_expr8_method_call_import()
3195+ var lines =<< trim END
3196+ vim9script
3197+ export def Square(items: list<number>): list<number>
3198+ return map(items, (_, i) => i * i)
3199+ enddef
3200+ END
3201+ call writefile(lines, 'Xsquare.vim')
3202+
3203+ lines =<< trim END
3204+ vim9script
3205+ import './Xsquare.vim'
3206+
3207+ def Test(): list<number>
3208+ return range(5)
3209+ ->Xsquare.Square()
3210+ ->map((_, i) => i * 10)
3211+ enddef
3212+
3213+ assert_equal([0, 10, 40, 90, 160], Test())
3214+ END
3215+ CheckScriptSuccess(lines)
3216+
3217+ delete('Xsquare.vim')
3218+enddef
3219+
3220+
3221+def Test_expr8_not()
31963222 var lines =<< trim END
31973223 assert_equal(true, !'')
31983224 assert_equal(true, ![])
@@ -3244,7 +3270,7 @@
32443270
32453271 let g:anumber = 42
32463272
3247-def Test_expr7_negate()
3273+def Test_expr8_negate()
32483274 var lines =<< trim END
32493275 var nr = 1
32503276 assert_equal(-1, -nr)
@@ -3253,7 +3279,7 @@
32533279 CheckDefAndScriptSuccess(lines)
32543280 enddef
32553281
3256-func Test_expr7_fails()
3282+func Test_expr8_fails()
32573283 call CheckDefFailure(["var x = (12"], "E1097:", 3)
32583284 call CheckScriptFailure(['vim9script', "var x = (12"], 'E110:', 2)
32593285
@@ -3313,7 +3339,7 @@
33133339 return a:one .. a:two
33143340 endfunc
33153341
3316-def Test_expr7_trailing()
3342+def Test_expr8_trailing()
33173343 var lines =<< trim END
33183344 # user function call
33193345 assert_equal(123, g:CallMe(123))
@@ -3349,7 +3375,7 @@
33493375 CheckDefAndScriptSuccess(lines)
33503376 enddef
33513377
3352-def Test_expr7_string_subscript()
3378+def Test_expr8_string_subscript()
33533379 var lines =<< trim END
33543380 var text = 'abcdef'
33553381 assert_equal('f', text[-1])
@@ -3448,7 +3474,7 @@
34483474 CheckDefAndScriptFailure(lines, ['E1012: Type mismatch; expected number but got string', 'E1030: Using a String as a Number: "2"'], 1)
34493475 enddef
34503476
3451-def Test_expr7_list_subscript()
3477+def Test_expr8_list_subscript()
34523478 var lines =<< trim END
34533479 var list = [0, 1, 2, 3, 4]
34543480 assert_equal(0, list[0])
@@ -3491,7 +3517,7 @@
34913517 CheckDefAndScriptSuccess(lines)
34923518 enddef
34933519
3494-def Test_expr7_dict_subscript()
3520+def Test_expr8_dict_subscript()
34953521 var lines =<< trim END
34963522 var l = [{lnum: 2}, {lnum: 1}]
34973523 var res = l[0].lnum > l[1].lnum
@@ -3512,7 +3538,7 @@
35123538 CheckDefAndScriptSuccess(lines)
35133539 enddef
35143540
3515-def Test_expr7_blob_subscript()
3541+def Test_expr8_blob_subscript()
35163542 var lines =<< trim END
35173543 var b = 0z112233
35183544 assert_equal(0x11, b[0])
@@ -3524,7 +3550,7 @@
35243550 CheckDefAndScriptSuccess(lines)
35253551 enddef
35263552
3527-def Test_expr7_subscript_linebreak()
3553+def Test_expr8_subscript_linebreak()
35283554 var lines =<< trim END
35293555 var range = range(
35303556 3)
@@ -3567,7 +3593,7 @@
35673593 CheckDefAndScriptFailure(lines, ['E1127:', 'E116:'], 2)
35683594 enddef
35693595
3570-func Test_expr7_trailing_fails()
3596+func Test_expr8_trailing_fails()
35713597 call CheckDefAndScriptFailure(['var l = [2]', 'l->((ll) => add(ll, 8))'], 'E107:', 2)
35723598 call CheckDefAndScriptFailure(['var l = [2]', 'l->((ll) => add(ll, 8)) ()'], 'E274:', 2)
35733599 endfunc
diff -r 19849ccc38a0 -r 63f8dbcf6a74 src/version.c
--- a/src/version.c Mon Jan 17 21:15:03 2022 +0100
+++ b/src/version.c Mon Jan 17 22:00:03 2022 +0100
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 4124,
755+/**/
754756 4123,
755757 /**/
756758 4122,
diff -r 19849ccc38a0 -r 63f8dbcf6a74 src/vim9expr.c
--- a/src/vim9expr.c Mon Jan 17 21:15:03 2022 +0100
+++ b/src/vim9expr.c Mon Jan 17 22:00:03 2022 +0100
@@ -1732,21 +1732,23 @@
17321732 }
17331733 else
17341734 {
1735+ int fail;
1736+ int save_len = cctx->ctx_ufunc->uf_lines.ga_len;
1737+
17351738 *paren = NUL;
1736- if (compile_expr8(arg, cctx, ppconst) == FAIL
1737- || *skipwhite(*arg) != NUL)
1739+ // do not look in the next line
1740+ cctx->ctx_ufunc->uf_lines.ga_len = 1;
1741+ fail = compile_expr8(arg, cctx, ppconst) == FAIL
1742+ || *skipwhite(*arg) != NUL;
1743+ *paren = '(';
1744+ cctx->ctx_ufunc->uf_lines.ga_len = save_len;
1745+ if (fail)
17381746 {
1739- *paren = '(';
17401747 semsg(_(e_invalid_expression_str), pstart);
17411748 return FAIL;
17421749 }
1743- *paren = '(';
17441750 }
17451751
1746- // Remember the next instruction index, where the instructions
1747- // for arguments are being written.
1748- expr_isn_end = cctx->ctx_instr.ga_len;
1749-
17501752 // Compile the arguments.
17511753 if (**arg != '(')
17521754 {
@@ -1756,6 +1758,11 @@
17561758 semsg(_(e_missing_parenthesis_str), *arg);
17571759 return FAIL;
17581760 }
1761+
1762+ // Remember the next instruction index, where the instructions
1763+ // for arguments are being written.
1764+ expr_isn_end = cctx->ctx_instr.ga_len;
1765+
17591766 *arg = skipwhite(*arg + 1);
17601767 if (compile_arguments(arg, cctx, &argcount, FALSE) == FAIL)
17611768 return FAIL;
旧リポジトリブラウザで表示