Mercurial > vim
changeset 24446:f388a033e568 v8.2.2763
patch 8.2.2763: Vim9: cannot use type in for loop unpack at script level
Commit: https://github.com/vim/vim/commit/a3589a0d6cdb314e70421c0f2e5a2d1abf68e597
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Apr 14 13:30:46 2021 +0200
patch 8.2.2763: Vim9: cannot use type in for loop unpack at script level
Problem: Vim9: cannot use type in for loop unpack at script level.
Solution: Advance over the type name.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 14 Apr 2021 13:45:04 +0200 |
parents | a06244a53881 |
children | bbe84a902d14 |
files | src/evalvars.c src/testdir/test_vim9_script.vim src/version.c |
diffstat | 3 files changed, 18 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/evalvars.c +++ b/src/evalvars.c @@ -1523,7 +1523,7 @@ ex_let_one( else { set_var_lval(&lv, p, tv, copy, flags, op, var_idx); - arg_end = p; + arg_end = lv.ll_name_end; } } clear_lval(&lv);
--- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -2336,8 +2336,22 @@ def Test_for_loop() endfor assert_equal(6, total) + # with type + total = 0 + for n: number in [1, 2, 3] + total += n + endfor + assert_equal(6, total) + + # unpack with type + var res = '' + for [n: number, s: string] in [[1, 'a'], [2, 'b']] + res ..= n .. s + endfor + assert_equal('1a2b', res) + # loop over string - var res = '' + res = '' for c in 'aéc̀d' res ..= c .. '-' endfor @@ -2364,13 +2378,6 @@ def Test_for_loop() assert_equal([{a: 'Cat', counter: 12}], foo) END CheckDefAndScriptSuccess(lines) - - # TODO: should also work at script level - var res = "" - for [n: number, s: string] in [[1, 'a'], [2, 'b']] - res ..= n .. s - endfor - assert_equal('1a2b', res) enddef def Test_for_loop_fails()