diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2023-10-21 11:59:42 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-10-21 11:59:42 +0200 |
commit | 0ab500dede4edd8d5aee7ddc63444537be527871 (patch) | |
tree | 96ebb872deec1d8ef086d9a133bd5167158c52fe /src | |
parent | a36acb7ac444a789440dc30e0f04d5427069face (diff) |
patch 9.0.2059: outstanding exceptions may be skippedv9.0.2059
Problem: outstanding exceptions may be skipped
Solution: When restoring exception state, process remaining outstanding
exceptions
closes: #13386
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/ex_eval.c | 15 | ||||
-rw-r--r-- | src/structs.h | 1 | ||||
-rw-r--r-- | src/testdir/test_user_func.vim | 61 | ||||
-rw-r--r-- | src/testdir/test_vim9_class.vim | 45 | ||||
-rw-r--r-- | src/testdir/test_vim9_script.vim | 58 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9class.c | 3 |
7 files changed, 169 insertions, 16 deletions
diff --git a/src/ex_eval.c b/src/ex_eval.c index e319dee0f0..79e9d94359 100644 --- a/src/ex_eval.c +++ b/src/ex_eval.c @@ -757,6 +757,7 @@ exception_state_save(exception_state_T *estate) estate->estate_did_throw = did_throw; estate->estate_need_rethrow = need_rethrow; estate->estate_trylevel = trylevel; + estate->estate_did_emsg = did_emsg; } /* @@ -765,11 +766,14 @@ exception_state_save(exception_state_T *estate) void exception_state_restore(exception_state_T *estate) { - if (current_exception == NULL) - current_exception = estate->estate_current_exception; - did_throw |= estate->estate_did_throw; - need_rethrow |= estate->estate_need_rethrow; - trylevel |= estate->estate_trylevel; + // Handle any outstanding exceptions before restoring the state + if (did_throw) + handle_did_throw(); + current_exception = estate->estate_current_exception; + did_throw = estate->estate_did_throw; + need_rethrow = estate->estate_need_rethrow; + trylevel = estate->estate_trylevel; + did_emsg = estate->estate_did_emsg; } /* @@ -782,6 +786,7 @@ exception_state_clear(void) did_throw = FALSE; need_rethrow = FALSE; trylevel = 0; + did_emsg = 0; } /* diff --git a/src/structs.h b/src/structs.h index a1a94b0ebb..209067b2e0 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1099,6 +1099,7 @@ struct exception_state_S int estate_did_throw; int estate_need_rethrow; int estate_trylevel; + int estate_did_emsg; }; #ifdef FEAT_SYN_HL diff --git a/src/testdir/test_user_func.vim b/src/testdir/test_user_func.vim index 8c3f33dd67..57a093c9c9 100644 --- a/src/testdir/test_user_func.vim +++ b/src/testdir/test_user_func.vim @@ -904,7 +904,68 @@ func Test_defer_after_exception() delfunc Defer delfunc Foo + delfunc Bar unlet g:callTrace endfunc +" Test for multiple deferred function which throw exceptions. +" Exceptions thrown by deferred functions should result in error messages but +" not propagated into the calling functions. +func Test_multidefer_with_exception() + let g:callTrace = [] + func Except() + let g:callTrace += [1] + throw 'InnerException' + let g:callTrace += [2] + endfunc + + func FirstDefer() + let g:callTrace += [3] + let g:callTrace += [4] + endfunc + + func SecondDeferWithExcept() + let g:callTrace += [5] + call Except() + let g:callTrace += [6] + endfunc + + func ThirdDefer() + let g:callTrace += [7] + let g:callTrace += [8] + endfunc + + func Foo() + let g:callTrace += [9] + defer FirstDefer() + defer SecondDeferWithExcept() + defer ThirdDefer() + let g:callTrace += [10] + endfunc + + let v:errmsg = '' + try + let g:callTrace += [11] + call Foo() + let g:callTrace += [12] + catch /TestException/ + let g:callTrace += [13] + catch + let g:callTrace += [14] + finally + let g:callTrace += [15] + endtry + let g:callTrace += [16] + + call assert_equal('E605: Exception not caught: InnerException', v:errmsg) + call assert_equal([11, 9, 10, 7, 8, 5, 1, 3, 4, 12, 15, 16], g:callTrace) + + unlet g:callTrace + delfunc Except + delfunc FirstDefer + delfunc SecondDeferWithExcept + delfunc ThirdDefer + delfunc Foo +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim index 59d5c9316d..02e99c84c3 100644 --- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -8347,10 +8347,10 @@ def Test_class_variable_as_operands() public static TruthyFn: func static list: list<any> = [] static four: number = 4 - static hello: string = 'hello' + static str: string = 'hello' - static def Hello(): string - return hello + static def Str(): string + return str enddef static def Four(): number @@ -8374,8 +8374,17 @@ def Test_class_variable_as_operands() assert_equal(16, 1 << Tests.four) assert_equal(8, Tests.four + four) assert_equal(8, four + Tests.four) - assert_equal('hellohello', Tests.hello .. hello) - assert_equal('hellohello', hello .. Tests.hello) + assert_equal('hellohello', Tests.str .. str) + assert_equal('hellohello', str .. Tests.str) + + # Using class variable for list indexing + var l = range(10) + assert_equal(4, l[Tests.four]) + assert_equal([4, 5, 6], l[Tests.four : Tests.four + 2]) + + # Using class variable for Dict key + var d = {hello: 'abc'} + assert_equal('abc', d[Tests.str]) enddef endclass @@ -8390,8 +8399,17 @@ def Test_class_variable_as_operands() assert_equal(16, 1 << Tests.four) assert_equal(8, Tests.four + Tests.Four()) assert_equal(8, Tests.Four() + Tests.four) - assert_equal('hellohello', Tests.hello .. Tests.Hello()) - assert_equal('hellohello', Tests.Hello() .. Tests.hello) + assert_equal('hellohello', Tests.str .. Tests.Str()) + assert_equal('hellohello', Tests.Str() .. Tests.str) + + # Using class variable for list indexing + var l = range(10) + assert_equal(4, l[Tests.four]) + assert_equal([4, 5, 6], l[Tests.four : Tests.four + 2]) + + # Using class variable for Dict key + var d = {hello: 'abc'} + assert_equal('abc', d[Tests.str]) enddef Tests.TruthyFn = Tests.Truthy @@ -8409,8 +8427,17 @@ def Test_class_variable_as_operands() assert_equal(16, 1 << Tests.four) assert_equal(8, Tests.four + Tests.Four()) assert_equal(8, Tests.Four() + Tests.four) - assert_equal('hellohello', Tests.hello .. Tests.Hello()) - assert_equal('hellohello', Tests.Hello() .. Tests.hello) + assert_equal('hellohello', Tests.str .. Tests.Str()) + assert_equal('hellohello', Tests.Str() .. Tests.str) + + # Using class variable for list indexing + var l = range(10) + assert_equal(4, l[Tests.four]) + assert_equal([4, 5, 6], l[Tests.four : Tests.four + 2]) + + # Using class variable for Dict key + var d = {hello: 'abc'} + assert_equal('abc', d[Tests.str]) END v9.CheckSourceSuccess(lines) enddef diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index 75a358e859..cac8484977 100644 --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -4725,6 +4725,64 @@ def Test_defer_after_exception() v9.CheckScriptSuccess(lines) enddef +" Test for multiple deferred function which throw exceptions. +" Exceptions thrown by deferred functions should result in error messages but +" not propagated into the calling functions. +def Test_multidefer_with_exception() + var lines =<< trim END + vim9script + + var callTrace: list<number> = [] + def Except() + callTrace += [1] + throw 'InnerException' + callTrace += [2] + enddef + + def FirstDefer() + callTrace += [3] + callTrace += [4] + enddef + + def SecondDeferWithExcept() + callTrace += [5] + Except() + callTrace += [6] + enddef + + def ThirdDefer() + callTrace += [7] + callTrace += [8] + enddef + + def Foo() + callTrace += [9] + defer FirstDefer() + defer SecondDeferWithExcept() + defer ThirdDefer() + callTrace += [10] + enddef + + v:errmsg = '' + try + callTrace += [11] + Foo() + callTrace += [12] + catch /TestException/ + callTrace += [13] + catch + callTrace += [14] + finally + callTrace += [15] + endtry + callTrace += [16] + + assert_equal('E605: Exception not caught: InnerException', v:errmsg) + assert_equal([11, 9, 10, 7, 8, 5, 1, 3, 4, 12, 15, 16], callTrace) + END + v9.CheckScriptSuccess(lines) +enddef + " Keep this last, it messes up highlighting. def Test_substitute_cmd() new diff --git a/src/version.c b/src/version.c index 87502234e1..8f0a9c3ba5 100644 --- a/src/version.c +++ b/src/version.c @@ -705,6 +705,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2059, +/**/ 2058, /**/ 2057, diff --git a/src/vim9class.c b/src/vim9class.c index b3930b1d6a..a05dcce3da 100644 --- a/src/vim9class.c +++ b/src/vim9class.c @@ -2340,8 +2340,7 @@ class_object_index( } if (did_emsg == did_emsg_save) - member_not_found_msg(cl, is_object ? VAR_OBJECT : VAR_CLASS, name, - len); + member_not_found_msg(cl, rettv->v_type, name, len); } return FAIL; |