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
@@ -1717,7 +1717,7 @@ | ||
1717 | 1717 | let $TESTVAR = 'testvar' |
1718 | 1718 | |
1719 | 1719 | " type casts |
1720 | -def Test_expr7t() | |
1720 | +def Test_expr7() | |
1721 | 1721 | var lines =<< trim END |
1722 | 1722 | var ls: list<string> = ['a', <string>g:string_empty] |
1723 | 1723 | var ln: list<number> = [<number>g:anint, <number>g:thefour] |
@@ -1743,7 +1743,7 @@ | ||
1743 | 1743 | enddef |
1744 | 1744 | |
1745 | 1745 | " test low level expression |
1746 | -def Test_expr7_number() | |
1746 | +def Test_expr8_number() | |
1747 | 1747 | # number constant |
1748 | 1748 | var lines =<< trim END |
1749 | 1749 | assert_equal(0, 0) |
@@ -1756,7 +1756,7 @@ | ||
1756 | 1756 | CheckDefAndScriptSuccess(lines) |
1757 | 1757 | enddef |
1758 | 1758 | |
1759 | -def Test_expr7_float() | |
1759 | +def Test_expr8_float() | |
1760 | 1760 | # float constant |
1761 | 1761 | if !has('float') |
1762 | 1762 | MissingFeature 'float' |
@@ -1771,7 +1771,7 @@ | ||
1771 | 1771 | endif |
1772 | 1772 | enddef |
1773 | 1773 | |
1774 | -def Test_expr7_blob() | |
1774 | +def Test_expr8_blob() | |
1775 | 1775 | # blob constant |
1776 | 1776 | var lines =<< trim END |
1777 | 1777 | assert_equal(g:blob_empty, 0z) |
@@ -1803,7 +1803,7 @@ | ||
1803 | 1803 | CheckDefAndScriptFailure(["var x = 0z123"], 'E973:', 1) |
1804 | 1804 | enddef |
1805 | 1805 | |
1806 | -def Test_expr7_string() | |
1806 | +def Test_expr8_string() | |
1807 | 1807 | # string constant |
1808 | 1808 | var lines =<< trim END |
1809 | 1809 | assert_equal(g:string_empty, '') |
@@ -1820,7 +1820,7 @@ | ||
1820 | 1820 | CheckDefAndScriptFailure(["var x = 'abc"], 'E115:', 1) |
1821 | 1821 | enddef |
1822 | 1822 | |
1823 | -def Test_expr7_vimvar() | |
1823 | +def Test_expr8_vimvar() | |
1824 | 1824 | v:errors = [] |
1825 | 1825 | var errs: list<string> = v:errors |
1826 | 1826 | CheckDefFailure(['var errs: list<number> = v:errors'], 'E1012:') |
@@ -1845,7 +1845,7 @@ | ||
1845 | 1845 | bwipe! |
1846 | 1846 | enddef |
1847 | 1847 | |
1848 | -def Test_expr7_special() | |
1848 | +def Test_expr8_special() | |
1849 | 1849 | # special constant |
1850 | 1850 | var lines =<< trim END |
1851 | 1851 | assert_equal(g:special_true, true) |
@@ -1882,7 +1882,7 @@ | ||
1882 | 1882 | CheckDefAndScriptFailure(['v:none = 22'], 'E46:', 1) |
1883 | 1883 | enddef |
1884 | 1884 | |
1885 | -def Test_expr7_list() | |
1885 | +def Test_expr8_list() | |
1886 | 1886 | # list |
1887 | 1887 | var lines =<< trim END |
1888 | 1888 | assert_equal(g:list_empty, []) |
@@ -1955,7 +1955,7 @@ | ||
1955 | 1955 | CheckDefAndScriptFailure(lines + ['echo numbers[a :b]'], 'E1004:', 4) |
1956 | 1956 | enddef |
1957 | 1957 | |
1958 | -def Test_expr7_list_vim9script() | |
1958 | +def Test_expr8_list_vim9script() | |
1959 | 1959 | var lines =<< trim END |
1960 | 1960 | var l = [ |
1961 | 1961 | 11, |
@@ -2043,7 +2043,7 @@ | ||
2043 | 2043 | x == 2 |
2044 | 2044 | enddef |
2045 | 2045 | |
2046 | -def Test_expr7_lambda() | |
2046 | +def Test_expr8_lambda() | |
2047 | 2047 | var lines =<< trim END |
2048 | 2048 | var La = () => 'result' |
2049 | 2049 | # comment |
@@ -2129,7 +2129,7 @@ | ||
2129 | 2129 | CheckDefAndScriptSuccess(lines) |
2130 | 2130 | enddef |
2131 | 2131 | |
2132 | -def Test_expr7_lambda_block() | |
2132 | +def Test_expr8_lambda_block() | |
2133 | 2133 | var lines =<< trim END |
2134 | 2134 | var Func = (s: string): string => { |
2135 | 2135 | return 'hello ' .. s |
@@ -2209,7 +2209,7 @@ | ||
2209 | 2209 | x == 2 |
2210 | 2210 | enddef |
2211 | 2211 | |
2212 | -def Test_expr7_new_lambda() | |
2212 | +def Test_expr8_new_lambda() | |
2213 | 2213 | var lines =<< trim END |
2214 | 2214 | var La = () => 'result' |
2215 | 2215 | assert_equal('result', La()) |
@@ -2294,7 +2294,7 @@ | ||
2294 | 2294 | CheckDefAndScriptFailure(['var Fx = (a) => [0', ' 1]'], 'E696:', 2) |
2295 | 2295 | enddef |
2296 | 2296 | |
2297 | -def Test_expr7_lambda_vim9script() | |
2297 | +def Test_expr8_lambda_vim9script() | |
2298 | 2298 | var lines =<< trim END |
2299 | 2299 | var v = 10->((a) => |
2300 | 2300 | a |
@@ -2313,7 +2313,7 @@ | ||
2313 | 2313 | CheckDefAndScriptSuccess(lines) |
2314 | 2314 | enddef |
2315 | 2315 | |
2316 | -def Test_expr7_funcref() | |
2316 | +def Test_expr8_funcref() | |
2317 | 2317 | var lines =<< trim END |
2318 | 2318 | def RetNumber(): number |
2319 | 2319 | return 123 |
@@ -2350,7 +2350,7 @@ | ||
2350 | 2350 | let g:test_space_dict = {'': 'empty', ' ': 'space'} |
2351 | 2351 | let g:test_hash_dict = #{one: 1, two: 2} |
2352 | 2352 | |
2353 | -def Test_expr7_dict() | |
2353 | +def Test_expr8_dict() | |
2354 | 2354 | # dictionary |
2355 | 2355 | var lines =<< trim END |
2356 | 2356 | assert_equal(g:dict_empty, {}) |
@@ -2461,7 +2461,7 @@ | ||
2461 | 2461 | CheckDefExecAndScriptFailure(['{}[getftype("file")]'], 'E716: Key not present in Dictionary: ""', 1) |
2462 | 2462 | enddef |
2463 | 2463 | |
2464 | -def Test_expr7_dict_vim9script() | |
2464 | +def Test_expr8_dict_vim9script() | |
2465 | 2465 | var lines =<< trim END |
2466 | 2466 | var d = { |
2467 | 2467 | ['one']: |
@@ -2592,7 +2592,7 @@ | ||
2592 | 2592 | CheckScriptSuccess(lines) |
2593 | 2593 | enddef |
2594 | 2594 | |
2595 | -def Test_expr7_dict_in_block() | |
2595 | +def Test_expr8_dict_in_block() | |
2596 | 2596 | var lines =<< trim END |
2597 | 2597 | vim9script |
2598 | 2598 | command MyCommand { |
@@ -2615,7 +2615,7 @@ | ||
2615 | 2615 | delcommand YourCommand |
2616 | 2616 | enddef |
2617 | 2617 | |
2618 | -def Test_expr7_call_2bool() | |
2618 | +def Test_expr8_call_2bool() | |
2619 | 2619 | var lines =<< trim END |
2620 | 2620 | vim9script |
2621 | 2621 |
@@ -2663,7 +2663,7 @@ | ||
2663 | 2663 | CheckDefExecAndScriptFailure(["var d: dict<number>", "d = g:list_empty"], 'E1012: Type mismatch; expected dict<number> but got list<unknown>', 2) |
2664 | 2664 | enddef |
2665 | 2665 | |
2666 | -def Test_expr7_any_index_slice() | |
2666 | +def Test_expr8_any_index_slice() | |
2667 | 2667 | var lines =<< trim END |
2668 | 2668 | # getting the one member should clear the list only after getting the item |
2669 | 2669 | assert_equal('bbb', ['aaa', 'bbb', 'ccc'][1]) |
@@ -2817,7 +2817,7 @@ | ||
2817 | 2817 | b:someVar = &fdm |
2818 | 2818 | enddef |
2819 | 2819 | |
2820 | -def Test_expr7_option() | |
2820 | +def Test_expr8_option() | |
2821 | 2821 | var lines =<< trim END |
2822 | 2822 | # option |
2823 | 2823 | set ts=11 |
@@ -2844,7 +2844,7 @@ | ||
2844 | 2844 | CheckDefAndScriptSuccess(lines) |
2845 | 2845 | enddef |
2846 | 2846 | |
2847 | -def Test_expr7_environment() | |
2847 | +def Test_expr8_environment() | |
2848 | 2848 | var lines =<< trim END |
2849 | 2849 | # environment variable |
2850 | 2850 | assert_equal('testvar', $TESTVAR) |
@@ -2856,7 +2856,7 @@ | ||
2856 | 2856 | CheckDefAndScriptFailure(["$"], ['E1002:', 'E15:'], 1) |
2857 | 2857 | enddef |
2858 | 2858 | |
2859 | -def Test_expr7_register() | |
2859 | +def Test_expr8_register() | |
2860 | 2860 | var lines =<< trim END |
2861 | 2861 | @a = 'register a' |
2862 | 2862 | assert_equal('register a', @a) |
@@ -2882,7 +2882,7 @@ | ||
2882 | 2882 | enddef |
2883 | 2883 | |
2884 | 2884 | " This is slow when run under valgrind. |
2885 | -def Test_expr7_namespace() | |
2885 | +def Test_expr8_namespace() | |
2886 | 2886 | var lines =<< trim END |
2887 | 2887 | g:some_var = 'some' |
2888 | 2888 | assert_equal('some', get(g:, 'some_var')) |
@@ -2911,7 +2911,7 @@ | ||
2911 | 2911 | CheckDefAndScriptSuccess(lines) |
2912 | 2912 | enddef |
2913 | 2913 | |
2914 | -def Test_expr7_namespace_loop_def() | |
2914 | +def Test_expr8_namespace_loop_def() | |
2915 | 2915 | var lines =<< trim END |
2916 | 2916 | # check using g: in a for loop more than DO_NOT_FREE_CNT times |
2917 | 2917 | var exists = 0 |
@@ -2930,8 +2930,8 @@ | ||
2930 | 2930 | enddef |
2931 | 2931 | |
2932 | 2932 | " 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() | |
2935 | 2935 | var lines =<< trim END |
2936 | 2936 | vim9script |
2937 | 2937 | # check using g: in a for loop more than DO_NOT_FREE_CNT times |
@@ -2950,7 +2950,7 @@ | ||
2950 | 2950 | CheckScriptSuccess(lines) |
2951 | 2951 | enddef |
2952 | 2952 | |
2953 | -def Test_expr7_parens() | |
2953 | +def Test_expr8_parens() | |
2954 | 2954 | # (expr) |
2955 | 2955 | var lines =<< trim END |
2956 | 2956 | assert_equal(4, (6 * 4) / 6) |
@@ -2982,7 +2982,7 @@ | ||
2982 | 2982 | CheckDefAndScriptSuccess(lines) |
2983 | 2983 | enddef |
2984 | 2984 | |
2985 | -def Test_expr7_negate_add() | |
2985 | +def Test_expr8_negate_add() | |
2986 | 2986 | var lines =<< trim END |
2987 | 2987 | assert_equal(-99, -99) |
2988 | 2988 | assert_equal(-99, - 99) |
@@ -3031,7 +3031,7 @@ | ||
3031 | 3031 | legacy return #{key: 'ok'}.key |
3032 | 3032 | enddef |
3033 | 3033 | |
3034 | -def Test_expr7_legacy_script() | |
3034 | +def Test_expr8_legacy_script() | |
3035 | 3035 | var lines =<< trim END |
3036 | 3036 | let s:legacy = 'legacy' |
3037 | 3037 | def GetLocal(): string |
@@ -3065,7 +3065,7 @@ | ||
3065 | 3065 | return arg |
3066 | 3066 | enddef |
3067 | 3067 | |
3068 | -def Test_expr7_call() | |
3068 | +def Test_expr8_call() | |
3069 | 3069 | var lines =<< trim END |
3070 | 3070 | assert_equal('yes', 'yes'->Echo()) |
3071 | 3071 | assert_equal(true, !range(5)->empty()) |
@@ -3098,7 +3098,7 @@ | ||
3098 | 3098 | delete('Xruntime', 'rf') |
3099 | 3099 | enddef |
3100 | 3100 | |
3101 | -def Test_expr7_method_call() | |
3101 | +def Test_expr8_method_call() | |
3102 | 3102 | var lines =<< trim END |
3103 | 3103 | new |
3104 | 3104 | setline(1, ['first', 'last']) |
@@ -3175,7 +3175,7 @@ | ||
3175 | 3175 | CheckDefExecFailure(lines, 'E1013:') |
3176 | 3176 | enddef |
3177 | 3177 | |
3178 | -def Test_expr7_method_call_linebreak() | |
3178 | +def Test_expr8_method_call_linebreak() | |
3179 | 3179 | # this was giving an error when skipping over the expression |
3180 | 3180 | var lines =<< trim END |
3181 | 3181 | vim9script |
@@ -3191,8 +3191,34 @@ | ||
3191 | 3191 | CheckScriptSuccess(lines) |
3192 | 3192 | enddef |
3193 | 3193 | |
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() | |
3196 | 3222 | var lines =<< trim END |
3197 | 3223 | assert_equal(true, !'') |
3198 | 3224 | assert_equal(true, ![]) |
@@ -3244,7 +3270,7 @@ | ||
3244 | 3270 | |
3245 | 3271 | let g:anumber = 42 |
3246 | 3272 | |
3247 | -def Test_expr7_negate() | |
3273 | +def Test_expr8_negate() | |
3248 | 3274 | var lines =<< trim END |
3249 | 3275 | var nr = 1 |
3250 | 3276 | assert_equal(-1, -nr) |
@@ -3253,7 +3279,7 @@ | ||
3253 | 3279 | CheckDefAndScriptSuccess(lines) |
3254 | 3280 | enddef |
3255 | 3281 | |
3256 | -func Test_expr7_fails() | |
3282 | +func Test_expr8_fails() | |
3257 | 3283 | call CheckDefFailure(["var x = (12"], "E1097:", 3) |
3258 | 3284 | call CheckScriptFailure(['vim9script', "var x = (12"], 'E110:', 2) |
3259 | 3285 |
@@ -3313,7 +3339,7 @@ | ||
3313 | 3339 | return a:one .. a:two |
3314 | 3340 | endfunc |
3315 | 3341 | |
3316 | -def Test_expr7_trailing() | |
3342 | +def Test_expr8_trailing() | |
3317 | 3343 | var lines =<< trim END |
3318 | 3344 | # user function call |
3319 | 3345 | assert_equal(123, g:CallMe(123)) |
@@ -3349,7 +3375,7 @@ | ||
3349 | 3375 | CheckDefAndScriptSuccess(lines) |
3350 | 3376 | enddef |
3351 | 3377 | |
3352 | -def Test_expr7_string_subscript() | |
3378 | +def Test_expr8_string_subscript() | |
3353 | 3379 | var lines =<< trim END |
3354 | 3380 | var text = 'abcdef' |
3355 | 3381 | assert_equal('f', text[-1]) |
@@ -3448,7 +3474,7 @@ | ||
3448 | 3474 | CheckDefAndScriptFailure(lines, ['E1012: Type mismatch; expected number but got string', 'E1030: Using a String as a Number: "2"'], 1) |
3449 | 3475 | enddef |
3450 | 3476 | |
3451 | -def Test_expr7_list_subscript() | |
3477 | +def Test_expr8_list_subscript() | |
3452 | 3478 | var lines =<< trim END |
3453 | 3479 | var list = [0, 1, 2, 3, 4] |
3454 | 3480 | assert_equal(0, list[0]) |
@@ -3491,7 +3517,7 @@ | ||
3491 | 3517 | CheckDefAndScriptSuccess(lines) |
3492 | 3518 | enddef |
3493 | 3519 | |
3494 | -def Test_expr7_dict_subscript() | |
3520 | +def Test_expr8_dict_subscript() | |
3495 | 3521 | var lines =<< trim END |
3496 | 3522 | var l = [{lnum: 2}, {lnum: 1}] |
3497 | 3523 | var res = l[0].lnum > l[1].lnum |
@@ -3512,7 +3538,7 @@ | ||
3512 | 3538 | CheckDefAndScriptSuccess(lines) |
3513 | 3539 | enddef |
3514 | 3540 | |
3515 | -def Test_expr7_blob_subscript() | |
3541 | +def Test_expr8_blob_subscript() | |
3516 | 3542 | var lines =<< trim END |
3517 | 3543 | var b = 0z112233 |
3518 | 3544 | assert_equal(0x11, b[0]) |
@@ -3524,7 +3550,7 @@ | ||
3524 | 3550 | CheckDefAndScriptSuccess(lines) |
3525 | 3551 | enddef |
3526 | 3552 | |
3527 | -def Test_expr7_subscript_linebreak() | |
3553 | +def Test_expr8_subscript_linebreak() | |
3528 | 3554 | var lines =<< trim END |
3529 | 3555 | var range = range( |
3530 | 3556 | 3) |
@@ -3567,7 +3593,7 @@ | ||
3567 | 3593 | CheckDefAndScriptFailure(lines, ['E1127:', 'E116:'], 2) |
3568 | 3594 | enddef |
3569 | 3595 | |
3570 | -func Test_expr7_trailing_fails() | |
3596 | +func Test_expr8_trailing_fails() | |
3571 | 3597 | call CheckDefAndScriptFailure(['var l = [2]', 'l->((ll) => add(ll, 8))'], 'E107:', 2) |
3572 | 3598 | call CheckDefAndScriptFailure(['var l = [2]', 'l->((ll) => add(ll, 8)) ()'], 'E274:', 2) |
3573 | 3599 | endfunc |
@@ -751,6 +751,8 @@ | ||
751 | 751 | static int included_patches[] = |
752 | 752 | { /* Add new patch number below this line */ |
753 | 753 | /**/ |
754 | + 4124, | |
755 | +/**/ | |
754 | 756 | 4123, |
755 | 757 | /**/ |
756 | 758 | 4122, |
@@ -1732,21 +1732,23 @@ | ||
1732 | 1732 | } |
1733 | 1733 | else |
1734 | 1734 | { |
1735 | + int fail; | |
1736 | + int save_len = cctx->ctx_ufunc->uf_lines.ga_len; | |
1737 | + | |
1735 | 1738 | *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) | |
1738 | 1746 | { |
1739 | - *paren = '('; | |
1740 | 1747 | semsg(_(e_invalid_expression_str), pstart); |
1741 | 1748 | return FAIL; |
1742 | 1749 | } |
1743 | - *paren = '('; | |
1744 | 1750 | } |
1745 | 1751 | |
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 | - | |
1750 | 1752 | // Compile the arguments. |
1751 | 1753 | if (**arg != '(') |
1752 | 1754 | { |
@@ -1756,6 +1758,11 @@ | ||
1756 | 1758 | semsg(_(e_missing_parenthesis_str), *arg); |
1757 | 1759 | return FAIL; |
1758 | 1760 | } |
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 | + | |
1759 | 1766 | *arg = skipwhite(*arg + 1); |
1760 | 1767 | if (compile_arguments(arg, cctx, &argcount, FALSE) == FAIL) |
1761 | 1768 | return FAIL; |