]> granicus.if.org Git - vim/commitdiff
patch 8.2.2763: Vim9: cannot use type in for loop unpack at script level v8.2.2763
authorBram Moolenaar <Bram@vim.org>
Wed, 14 Apr 2021 11:30:46 +0000 (13:30 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 14 Apr 2021 11:30:46 +0000 (13:30 +0200)
Problem:    Vim9: cannot use type in for loop unpack at script level.
Solution:   Advance over the type name.

src/evalvars.c
src/testdir/test_vim9_script.vim
src/version.c

index eb9ad6da1613d5eea1c83d8cc3e9fdeea9dd345e..ebfc42b187b9dffc75cd2bf68576a50f87c65093 100644 (file)
@@ -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);
index af7e5fdbb6122017e25812c8058ec3f3da99e001..03da2fd86f925af8da41f040359a3f0639e238f3 100644 (file)
@@ -2336,8 +2336,22 @@ def Test_for_loop()
       endfor
       assert_equal(6, total)
 
-      # loop over string
+      # 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
+      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()
index 72da5f91ba8138c9ed9f96bb01f3de886da29701..3dee026c1dd1c62328f7a99c3b8bc559e005dcf2 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2763,
 /**/
     2762,
 /**/