diff --git a/src/compiler.h b/src/compiler.h index 6189d92b..f8a18ee9 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -786,7 +786,7 @@ __SUBSCR_END: if(match(TK("(")) && !match(TK(")"))){ EXPR(false); consume(TK(")")); }else{ - ctx()->emit(OP_LOAD_NONE, BC_NOARG, BC_KEEPLINE); + ctx()->emit(OP_LOAD_NONE, BC_NOARG, kw_line); } ctx()->emit(OP_RAISE, dummy_t, kw_line); consume_end_stmt(); diff --git a/src/frame.h b/src/frame.h index 4d93ca1f..bc6ad1e0 100644 --- a/src/frame.h +++ b/src/frame.h @@ -166,7 +166,7 @@ struct Frame { // get the stack size of the try block (depth of for loops) int _stack_size = co->blocks[block].for_loop_depth; if(stack_size() < _stack_size) throw std::runtime_error("invalid stack size"); - _s->reset(actual_sp_base() + _stack_size); // rollback the stack + _s->reset(actual_sp_base() + _locals.size() + _stack_size); // rollback the stack _s->push(obj); // push exception object _next_ip = co->blocks[block].end; return true; diff --git a/src/vm.h b/src/vm.h index 5ed6ce33..afe81a59 100644 --- a/src/vm.h +++ b/src/vm.h @@ -983,7 +983,7 @@ inline std::string _opcode_argstr(VM* vm, Bytecode byte, const CodeObject* co){ break; case OP_LOAD_NAME: case OP_LOAD_GLOBAL: case OP_LOAD_NONLOCAL: case OP_STORE_GLOBAL: case OP_LOAD_ATTR: case OP_LOAD_METHOD: case OP_STORE_ATTR: case OP_DELETE_ATTR: - case OP_IMPORT_NAME: case OP_BEGIN_CLASS: + case OP_IMPORT_NAME: case OP_BEGIN_CLASS: case OP_RAISE: case OP_DELETE_GLOBAL: case OP_INC_GLOBAL: case OP_DEC_GLOBAL: argStr += fmt(" (", StrName(byte.arg).sv(), ")"); break; diff --git a/tests/41_exception.py b/tests/41_exception.py index c7c4e878..a15aadbe 100644 --- a/tests/41_exception.py +++ b/tests/41_exception.py @@ -71,3 +71,14 @@ try: exit(1) except AssertionError: pass + +def f(a: list): + try: + raise ValueError + exit(1) + except: + pass + a[0] = 1 +a = [0] +f(a) +assert a == [1] \ No newline at end of file