From 36b50a25f9e33c3d83e685157c574aeffd32b406 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Tue, 23 Sep 2014 18:22:51 +0400 Subject: [PATCH] Changed generating logic for named functions Generate it as a sequence of statements when it's possible --- .../org/jetbrains/jet/codegen/ExpressionCodegen.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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); } }