diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index a5fe85d1c..5fe02fbec 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -1512,7 +1512,9 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) { case "panic": emit.Opcode(c.prog.BinWriter, opcode.THROW) case "recover": - c.emitLoadByIndex(varGlobal, c.exceptionIndex) + if !c.scope.voidCalls[expr] { + c.emitLoadByIndex(varGlobal, c.exceptionIndex) + } emit.Opcode(c.prog.BinWriter, opcode.PUSHNULL) c.emitStoreByIndex(varGlobal, c.exceptionIndex) case "ToInteger", "ToByteArray", "ToBool": diff --git a/pkg/compiler/defer_test.go b/pkg/compiler/defer_test.go index 4a2f8f3b0..d9b39ea07 100644 --- a/pkg/compiler/defer_test.go +++ b/pkg/compiler/defer_test.go @@ -128,8 +128,8 @@ func TestRecover(t *testing.T) { return h() + a } func h() int { - defer func() { a += 2; _ = recover() }() - defer func() { a *= 3; _ = recover(); panic("again") }() + defer func() { a += 2; recover() }() + defer func() { a *= 3; recover(); panic("again") }() a = 1 panic("msg") return a