compiler: handle void call to recover()
Other builtins such as `len` and `make` can be ignored, because not-assigning `make` result is catched by parser.
This commit is contained in:
parent
7d61a567d5
commit
3d8c7af66c
2 changed files with 5 additions and 3 deletions
|
@ -1512,7 +1512,9 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
|
||||||
case "panic":
|
case "panic":
|
||||||
emit.Opcode(c.prog.BinWriter, opcode.THROW)
|
emit.Opcode(c.prog.BinWriter, opcode.THROW)
|
||||||
case "recover":
|
case "recover":
|
||||||
c.emitLoadByIndex(varGlobal, c.exceptionIndex)
|
if !c.scope.voidCalls[expr] {
|
||||||
|
c.emitLoadByIndex(varGlobal, c.exceptionIndex)
|
||||||
|
}
|
||||||
emit.Opcode(c.prog.BinWriter, opcode.PUSHNULL)
|
emit.Opcode(c.prog.BinWriter, opcode.PUSHNULL)
|
||||||
c.emitStoreByIndex(varGlobal, c.exceptionIndex)
|
c.emitStoreByIndex(varGlobal, c.exceptionIndex)
|
||||||
case "ToInteger", "ToByteArray", "ToBool":
|
case "ToInteger", "ToByteArray", "ToBool":
|
||||||
|
|
|
@ -128,8 +128,8 @@ func TestRecover(t *testing.T) {
|
||||||
return h() + a
|
return h() + a
|
||||||
}
|
}
|
||||||
func h() int {
|
func h() int {
|
||||||
defer func() { a += 2; _ = recover() }()
|
defer func() { a += 2; recover() }()
|
||||||
defer func() { a *= 3; _ = recover(); panic("again") }()
|
defer func() { a *= 3; recover(); panic("again") }()
|
||||||
a = 1
|
a = 1
|
||||||
panic("msg")
|
panic("msg")
|
||||||
return a
|
return a
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue