compiler: do not emit RET twice for nested BlockStmt

When function finishes with `*ast.BlockStmt`, last return
in that block should be looked for.
This commit is contained in:
Evgeniy Stratonikov 2021-02-05 14:31:45 +03:00
parent 6445e4be91
commit 1f238ce6fd
2 changed files with 11 additions and 5 deletions

View file

@ -440,7 +440,7 @@ func (c *codegen) convertFuncDecl(file ast.Node, decl *ast.FuncDecl, pkg *types.
// If we have reached the end of the function without encountering `return` statement,
// we should clean alt.stack manually.
// This can be the case with void and named-return functions.
if !isInit && !isDeploy && !lastStmtIsReturn(decl) {
if !isInit && !isDeploy && !lastStmtIsReturn(decl.Body) {
c.saveSequencePoint(decl.Body)
emit.Opcodes(c.prog.BinWriter, opcode.RET)
}