diff src/testdir/test_vim9_script.vim @ 22975:a943b175586a v8.2.2034

patch 8.2.2034: Vim9: list unpack in for statement not compiled yet Commit: https://github.com/vim/vim/commit/792f786aad8409ca9ab895392742643a5b6aed8f Author: Bram Moolenaar <Bram@vim.org> Date: Mon Nov 23 08:31:18 2020 +0100 patch 8.2.2034: Vim9: list unpack in for statement not compiled yet Problem: Vim9: list unpack in for statement not compiled yet. Solution: Compile list unpack. (closes https://github.com/vim/vim/issues/7345)
author Bram Moolenaar <Bram@vim.org>
date Mon, 23 Nov 2020 08:45:04 +0100
parents 00b0275ffe7f
children df0548b649c1
line wrap: on
line diff
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -1862,6 +1862,44 @@ def Test_for_loop_fails()
   CheckDefFailure(['for i in range(3)', 'echo 3'], 'E170:')
 enddef
 
+def Test_for_loop_unpack()
+  var result = []
+  for [v1, v2] in [[1, 2], [3, 4]]
+    result->add(v1)
+    result->add(v2)
+  endfor
+  assert_equal([1, 2, 3, 4], result)
+
+  result = []
+  for [v1, v2; v3] in [[1, 2], [3, 4, 5, 6]]
+    result->add(v1)
+    result->add(v2)
+    result->add(v3)
+  endfor
+  assert_equal([1, 2, [], 3, 4, [5, 6]], result)
+
+  var lines =<< trim END
+      for [v1, v2] in [[1, 2, 3], [3, 4]]
+        echo v1 v2
+      endfor
+  END
+  CheckDefExecFailure(lines, 'E710:', 1)
+
+  lines =<< trim END
+      for [v1, v2] in [[1], [3, 4]]
+        echo v1 v2
+      endfor
+  END
+  CheckDefExecFailure(lines, 'E711:', 1)
+
+  lines =<< trim END
+      for [v1, v1] in [[1, 2], [3, 4]]
+        echo v1
+      endfor
+  END
+  CheckDefExecFailure(lines, 'E1017:', 1)
+enddef
+
 def Test_while_loop()
   var result = ''
   var cnt = 0