diff src/testdir/test_vim9_disassemble.vim @ 21188:d73b6ba20053 v8.2.1145

patch 8.2.1145: Vim9: "for" only accepts a list at compile time Commit: https://github.com/vim/vim/commit/0ad3e894d75236915e67dfbbcc821b6bb3c05d91 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 5 21:38:11 2020 +0200 patch 8.2.1145: Vim9: "for" only accepts a list at compile time Problem: Vim9: "for" only accepts a list at compile time. Solution: Also accept a list at runtime.
author Bram Moolenaar <Bram@vim.org>
date Sun, 05 Jul 2020 21:45:04 +0200
parents 0653b9b72091
children 3f14e0d4a4dd
line wrap: on
line diff
--- a/src/testdir/test_vim9_disassemble.vim
+++ b/src/testdir/test_vim9_disassemble.vim
@@ -727,6 +727,43 @@ def Test_disassemble_for_loop()
         instr)
 enddef
 
+def ForLoopEval(): string
+  let res = ""
+  for str in eval('["one", "two"]')
+    res ..= str
+  endfor
+  return res
+enddef
+
+def Test_disassemble_for_loop_eval()
+  assert_equal('onetwo', ForLoopEval())
+  let instr = execute('disassemble ForLoopEval')
+  assert_match('ForLoopEval\_s*' ..
+        'let res = ""\_s*' ..
+        '\d PUSHS ""\_s*' ..
+        '\d STORE $0\_s*' ..
+        'for str in eval(''\["one", "two"\]'')\_s*' ..
+        '\d STORE -1 in $1\_s*' ..
+        '\d PUSHS "\["one", "two"\]"\_s*' ..
+        '\d BCALL eval(argc 1)\_s*' ..
+        '\d CHECKTYPE list stack\[-1\]\_s*' ..
+        '\d FOR $1 -> \d\+\_s*' ..
+        '\d STORE $2\_s*' ..
+        'res ..= str\_s*' ..
+        '\d\+ LOAD $0\_s*' ..
+        '\d\+ LOAD $2\_s*' ..
+        '\d\+ CHECKTYPE string stack\[-1\]\_s*' ..
+        '\d\+ CONCAT\_s*' ..
+        '\d\+ STORE $0\_s*' ..
+        'endfor\_s*' ..
+        '\d\+ JUMP -> 6\_s*' ..
+        '\d\+ DROP\_s*' ..
+        'return res\_s*' ..
+        '\d\+ LOAD $0\_s*' ..
+        '\d\+ RETURN',
+        instr)
+enddef
+
 let g:number = 42
 
 def Computing()