Mirror of the Vim source from https://github.com/vim/vim
修訂 | 56907027dba7a4fbfc648a209df12c18bad87d75 (tree) |
---|---|
時間 | 2020-10-29 01:00:03 |
作者 | Bram Moolenaar <Bram@vim....> |
Commiter | Bram Moolenaar |
patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Commit: https://github.com/vim/vim/commit/171fb923b8f8da9fb0db1c8c86e35cf4e1339000
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Oct 28 16:54:47 2020 +0100
@@ -1462,6 +1462,35 @@ | ||
1462 | 1462 | call delete('XTest_silent_echo') |
1463 | 1463 | endfunc |
1464 | 1464 | |
1465 | +def SilentlyError() | |
1466 | + execute('silent! invalid') | |
1467 | + g:did_it = 'yes' | |
1468 | +enddef | |
1469 | + | |
1470 | +"func UserError() | |
1471 | +" silent! invalid | |
1472 | +"endfunc | |
1473 | +" | |
1474 | +"def SilentlyUserError() | |
1475 | +" UserError() | |
1476 | +" g:did_it = 'yes' | |
1477 | +"enddef | |
1478 | + | |
1479 | +" This can't be a :def function, because the assert would not be reached. | |
1480 | +" And this must not be inside a try/endtry. | |
1481 | +func Test_ignore_silent_error() | |
1482 | + let g:did_it = 'no' | |
1483 | + call SilentlyError() | |
1484 | + call assert_equal('yes', g:did_it) | |
1485 | + | |
1486 | +" this doesn't work yet | |
1487 | +" let g:did_it = 'no' | |
1488 | +" call SilentlyUserError() | |
1489 | +" call assert_equal('yes', g:did_it) | |
1490 | + | |
1491 | + unlet g:did_it | |
1492 | +endfunc | |
1493 | + | |
1465 | 1494 | def Fibonacci(n: number): number |
1466 | 1495 | if n < 2 |
1467 | 1496 | return n |
@@ -751,6 +751,8 @@ | ||
751 | 751 | static int included_patches[] = |
752 | 752 | { /* Add new patch number below this line */ |
753 | 753 | /**/ |
754 | + 1916, | |
755 | +/**/ | |
754 | 756 | 1915, |
755 | 757 | /**/ |
756 | 758 | 1914, |
@@ -550,7 +550,7 @@ | ||
550 | 550 | { |
551 | 551 | typval_T argvars[MAX_FUNC_ARGS]; |
552 | 552 | int idx; |
553 | - int called_emsg_before = called_emsg; | |
553 | + int did_emsg_before = did_emsg; | |
554 | 554 | ectx_T *prev_ectx = current_ectx; |
555 | 555 | |
556 | 556 | if (call_prepare(argcount, argvars, ectx) == FAIL) |
@@ -566,7 +566,7 @@ | ||
566 | 566 | for (idx = 0; idx < argcount; ++idx) |
567 | 567 | clear_tv(&argvars[idx]); |
568 | 568 | |
569 | - if (called_emsg != called_emsg_before) | |
569 | + if (did_emsg != did_emsg_before) | |
570 | 570 | return FAIL; |
571 | 571 | return OK; |
572 | 572 | } |
@@ -834,6 +834,7 @@ | ||
834 | 834 | msglist_T *private_msg_list = NULL; |
835 | 835 | cmdmod_T save_cmdmod; |
836 | 836 | int restore_cmdmod = FALSE; |
837 | + int trylevel_at_start = trylevel; | |
837 | 838 | |
838 | 839 | // Get pointer to item in the stack. |
839 | 840 | #define STACK_TV(idx) (((typval_T *)ectx.ec_stack.ga_data) + idx) |
@@ -2866,7 +2867,8 @@ | ||
2866 | 2867 | continue; |
2867 | 2868 | |
2868 | 2869 | on_error: |
2869 | - if (trylevel == 0) | |
2870 | + // If we are not inside a try-catch started here, abort execution. | |
2871 | + if (trylevel <= trylevel_at_start) | |
2870 | 2872 | goto failed; |
2871 | 2873 | } |
2872 | 2874 |