diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-03-03 15:11:20 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-03-03 15:11:20 +0000 |
commit | 28bf649a5732ffe5a47951b5e437b765cebc5b38 (patch) | |
tree | 25b5a1c3796dc675bf3a32d7016bb6946fed3386 /src/ex_eval.c | |
parent | 1fc34225acbee5ddca2b9ec3f82b3014d385b7f8 (diff) |
patch 8.2.4499: Vim9: at the script level declarations leak to next blockv8.2.4499
Problem: Vim9: at the script level declarations leak from try block to
catch and finally block.
Solution: End the block and start a new one. (closes #9883)
Diffstat (limited to 'src/ex_eval.c')
-rw-r--r-- | src/ex_eval.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ex_eval.c b/src/ex_eval.c index ab30798622..e3c544b892 100644 --- a/src/ex_eval.c +++ b/src/ex_eval.c @@ -1827,6 +1827,16 @@ ex_catch(exarg_T *eap) cstack->cs_flags[idx] |= CSF_ACTIVE | CSF_CAUGHT; did_emsg = got_int = did_throw = FALSE; catch_exception((except_T *)cstack->cs_exception[idx]); + + if (cstack->cs_idx >= 0 + && (cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) + { + // Variables declared in the previous block can no longer be + // used. + leave_block(cstack); + enter_block(cstack); + } + // It's mandatory that the current exception is stored in the cstack // so that it can be discarded at the next ":catch", ":finally", or // ":endtry" or when the catch clause is left by a ":continue", @@ -1930,6 +1940,15 @@ ex_finally(exarg_T *eap) */ cleanup_conditionals(cstack, CSF_TRY, FALSE); + if (cstack->cs_idx >= 0 + && (cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) + { + // Variables declared in the previous block can no longer be + // used. + leave_block(cstack); + enter_block(cstack); + } + /* * Make did_emsg, got_int, did_throw pending. If set, they overrule * a pending ":continue", ":break", ":return", or ":finish". Then |