diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 609e89eed09..add5162c15a 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -1668,10 +1668,18 @@ public class ExpressionCodegen extends JetVisitor implem } public void returnExpression(JetExpression expr) { - StackValue lastValue = gen(expr); + boolean isBlockedNamedFunction = expr instanceof JetBlockExpression && expr.getParent() instanceof JetNamedFunction; + // If generating body for named block-bodied function, generate it as sequence of statements + gen(expr, isBlockedNamedFunction ? Type.VOID_TYPE : returnType); + + // If it does not end with return we should return something + // because if we don't there can be VerifyError (specific cases with Nothing-typed expressions) if (!endsWithReturn(expr)) { - lastValue.put(returnType, v); + if (isBlockedNamedFunction && !Type.VOID_TYPE.equals(expressionType(expr))) { + StackValue.none().put(returnType, v); + } + v.areturn(returnType); } }