comparison src/vim9cmds.c @ 27084:6fc63c6a7ee7 v8.2.4071

patch 8.2.4071: Vim9: no detection of return in try/endtry Commit: https://github.com/vim/vim/commit/53c296112edd8471eb63afbca03f96bad164c813 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 12 16:18:18 2022 +0000 patch 8.2.4071: Vim9: no detection of return in try/endtry Problem: Vim9: no detection of return in try/endtry. (Dominique Pell?) Solution: Check if any of the blocks inside try/endtry did not end in return.
author Bram Moolenaar <Bram@vim.org>
date Wed, 12 Jan 2022 17:30:07 +0100
parents 8dc4782b60ff
children 47dbeda35910
comparison
equal deleted inserted replaced
27083:15f9359846ad 27084:6fc63c6a7ee7
1341 if (scope->se_u.se_try.ts_caught_all) 1341 if (scope->se_u.se_try.ts_caught_all)
1342 { 1342 {
1343 emsg(_(e_catch_unreachable_after_catch_all)); 1343 emsg(_(e_catch_unreachable_after_catch_all));
1344 return NULL; 1344 return NULL;
1345 } 1345 }
1346 if (!cctx->ctx_had_return)
1347 scope->se_u.se_try.ts_no_return = TRUE;
1346 1348
1347 if (cctx->ctx_skip != SKIP_YES) 1349 if (cctx->ctx_skip != SKIP_YES)
1348 { 1350 {
1349 #ifdef FEAT_PROFILE 1351 #ifdef FEAT_PROFILE
1350 // the profile-start should be after the jump 1352 // the profile-start should be after the jump
1496 // Previous catch without match jumps here 1498 // Previous catch without match jumps here
1497 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_catch_label; 1499 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_catch_label;
1498 isn->isn_arg.jump.jump_where = this_instr; 1500 isn->isn_arg.jump.jump_where = this_instr;
1499 scope->se_u.se_try.ts_catch_label = 0; 1501 scope->se_u.se_try.ts_catch_label = 0;
1500 } 1502 }
1503 scope->se_u.se_try.ts_has_finally = TRUE;
1501 if (generate_instr(cctx, ISN_FINALLY) == NULL) 1504 if (generate_instr(cctx, ISN_FINALLY) == NULL)
1502 return NULL; 1505 return NULL;
1503 } 1506 }
1504 1507
1505 return arg; 1508 return arg;
1564 isn_T *isn = ((isn_T *)instr->ga_data) 1567 isn_T *isn = ((isn_T *)instr->ga_data)
1565 + scope->se_u.se_try.ts_catch_label; 1568 + scope->se_u.se_try.ts_catch_label;
1566 isn->isn_arg.jump.jump_where = instr->ga_len; 1569 isn->isn_arg.jump.jump_where = instr->ga_len;
1567 } 1570 }
1568 } 1571 }
1572
1573 // If there is a finally clause that ends in return then we will return.
1574 // If one of the blocks didn't end in "return" or we did not catch all
1575 // exceptions reset the had_return flag.
1576 if (!(scope->se_u.se_try.ts_has_finally && cctx->ctx_had_return)
1577 && (scope->se_u.se_try.ts_no_return
1578 || !scope->se_u.se_try.ts_caught_all))
1579 cctx->ctx_had_return = FALSE;
1569 1580
1570 compile_endblock(cctx); 1581 compile_endblock(cctx);
1571 1582
1572 if (cctx->ctx_skip != SKIP_YES) 1583 if (cctx->ctx_skip != SKIP_YES)
1573 { 1584 {