diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index c369aa4fa35f9..bbe52384d2ebc 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -244,7 +244,6 @@ private static boolean isEmptyExpression(JetElement expr) { @Override public StackValue visitIfExpression(JetIfExpression expression, StackValue receiver) { Type asmType = expressionType(expression); - StackValue condition = gen(expression.getCondition()); JetExpression thenExpression = expression.getThen(); JetExpression elseExpression = expression.getElse(); @@ -261,16 +260,19 @@ public StackValue visitIfExpression(JetIfExpression expression, StackValue recei StackValue.putTuple0Instance(v); return StackValue.onStack(asmType); } + StackValue condition = gen(expression.getCondition()); return generateSingleBranchIf(condition, elseExpression, false); } else { if (isEmptyExpression(elseExpression)) { + StackValue condition = gen(expression.getCondition()); return generateSingleBranchIf(condition, thenExpression, true); } } Label elseLabel = new Label(); + StackValue condition = gen(expression.getCondition()); condition.condJump(elseLabel, true, v); // == 0, i.e. false Label end = new Label(); diff --git a/compiler/testData/codegen/regressions/kt2482.kt b/compiler/testData/codegen/regressions/kt2482.kt new file mode 100644 index 0000000000000..c9c6d6e769235 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2482.kt @@ -0,0 +1,9 @@ +public fun box() : String { + if ( 0 == 0 ) { // Does not crash if either this... + if ( 0 == 0 ) { // ...or this is changed to if ( true ) + // Does not crash if the following is uncommented. + //println("foo") + } + } + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java index b45561cb7c115..b751902d51fcb 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java @@ -486,4 +486,9 @@ public void testKt2485() { createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); blackBoxMultiFile("regressions/kt2485.kt"); } + + public void testKt2482() { + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + blackBoxMultiFile("regressions/kt2482.kt"); + } }