for completely empty if statement, put on stack the Tuple0 instance, not its condition (KT-2062)

#KT-2062 Fixed
This commit is contained in:
Dmitry Jemerov
2012-06-08 17:43:02 +02:00
parent 5c21564b05
commit 56310599a5
4 changed files with 15 additions and 2 deletions
@@ -245,7 +245,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
if (isEmptyExpression(thenExpression)) {
if (isEmptyExpression(elseExpression)) {
condition.put(asmType, v);
if (!asmType.equals(JetTypeMapper.TUPLE0_TYPE)) {
throw new CompilationException("Completely empty 'if' is expected to have Unit type", null, expression);
}
StackValue.putTuple0Instance(v);
return StackValue.onStack(asmType);
}
return generateSingleBranchIf(condition, elseExpression, false);
@@ -260,7 +260,7 @@ public abstract class StackValue {
}
}
protected static void putTuple0Instance(InstructionAdapter v) {
public static void putTuple0Instance(InstructionAdapter v) {
v.visitFieldInsn(Opcodes.GETSTATIC, "jet/Tuple0", "INSTANCE", "Ljet/Tuple0;");
}
@@ -0,0 +1,5 @@
fun box(): String {
val a = if(true) {
}
return if (a.toString() == "()") "OK" else "fail"
}
@@ -346,4 +346,9 @@ public class ControlStructuresTest extends CodegenTestCase {
createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS);
blackBoxFile("regressions/kt1742.kt");
}
public void testKt2062() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS);
blackBoxFile("regressions/kt2062.kt");
}
}