diff --git a/pkg/compiler/analysis.go b/pkg/compiler/analysis.go index 0004db63b..880ce84fa 100644 --- a/pkg/compiler/analysis.go +++ b/pkg/compiler/analysis.go @@ -175,10 +175,16 @@ func (f funcUsage) funcUsed(name string) bool { } // lastStmtIsReturn checks if last statement of the declaration was return statement.. -func lastStmtIsReturn(decl *ast.FuncDecl) (b bool) { - if l := len(decl.Body.List); l != 0 { - _, ok := decl.Body.List[l-1].(*ast.ReturnStmt) - return ok +func lastStmtIsReturn(body *ast.BlockStmt) (b bool) { + if l := len(body.List); l != 0 { + switch inner := body.List[l-1].(type) { + case *ast.BlockStmt: + return lastStmtIsReturn(inner) + case *ast.ReturnStmt: + return true + default: + return false + } } return false } diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 4dceef1d1..ae98df43b 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -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) }