diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-02-13 15:02:46 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-02-13 15:02:46 +0100 |
commit | c150c09ec4f97636c6339f5687fdaa9f665095d2 (patch) | |
tree | 6ad97a4c1eff027184c75fda74555d4a97a04992 /src/testdir | |
parent | 31842cd0772b557eb9584a13740430db29de8a51 (diff) | |
download | vim-git-c150c09ec4f97636c6339f5687fdaa9f665095d2.tar.gz |
patch 8.2.2506: Vim9: :continue does not work correctly in a :try blockv8.2.2506
Problem: Vim9: :continue does not work correctly in a :try block
Solution: Add the TRYCLEANUP instruction. (closes #7827)
Diffstat (limited to 'src/testdir')
-rw-r--r-- | src/testdir/test_vim9_disassemble.vim | 57 | ||||
-rw-r--r-- | src/testdir/test_vim9_script.vim | 17 |
2 files changed, 74 insertions, 0 deletions
diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim index 1c5743248..4d7bbf63e 100644 --- a/src/testdir/test_vim9_disassemble.vim +++ b/src/testdir/test_vim9_disassemble.vim @@ -1111,6 +1111,63 @@ def Test_disassemble_for_loop_unpack() instr) enddef +def ForLoopContinue() + for nr in [1, 2] + try + echo "ok" + try + echo "deeper" + catch + continue + endtry + catch + echo "not ok" + endtry + endfor +enddef + +def Test_disassemble_for_loop_continue() + var instr = execute('disassemble ForLoopContinue') + assert_match('ForLoopContinue\_s*' .. + 'for nr in \[1, 2]\_s*' .. + '0 STORE -1 in $0\_s*' .. + '1 PUSHNR 1\_s*' .. + '2 PUSHNR 2\_s*' .. + '3 NEWLIST size 2\_s*' .. + '4 FOR $0 -> 22\_s*' .. + '5 STORE $1\_s*' .. + 'try\_s*' .. + '6 TRY catch -> 17, end -> 20\_s*' .. + 'echo "ok"\_s*' .. + '7 PUSHS "ok"\_s*' .. + '8 ECHO 1\_s*' .. + 'try\_s*' .. + '9 TRY catch -> 13, end -> 15\_s*' .. + 'echo "deeper"\_s*' .. + '10 PUSHS "deeper"\_s*' .. + '11 ECHO 1\_s*' .. + 'catch\_s*' .. + '12 JUMP -> 15\_s*' .. + '13 CATCH\_s*' .. + 'continue\_s*' .. + '14 TRY-CONTINUE 2 levels -> 4\_s*' .. + 'endtry\_s*' .. + '15 ENDTRY\_s*' .. + 'catch\_s*' .. + '16 JUMP -> 20\_s*' .. + '17 CATCH\_s*' .. + 'echo "not ok"\_s*' .. + '18 PUSHS "not ok"\_s*' .. + '19 ECHO 1\_s*' .. + 'endtry\_s*' .. + '20 ENDTRY\_s*' .. + 'endfor\_s*' .. + '21 JUMP -> 4\_s*' .. + '\d\+ DROP\_s*' .. + '\d\+ RETURN 0', + instr) +enddef + let g:number = 42 def TypeCast() diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index 17b996f17..85eea13fd 100644 --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -2201,6 +2201,23 @@ def Test_for_loop_unpack() CheckDefExecFailure(lines, 'E1017:', 1) enddef +def Test_for_loop_with_try_continue() + var looped = 0 + var cleanup = 0 + for i in range(3) + looped += 1 + try + eval [][0] + catch + continue + finally + cleanup += 1 + endtry + endfor + assert_equal(3, looped) + assert_equal(3, cleanup) +enddef + def Test_while_loop() var result = '' var cnt = 0 |