support putting the result of a dummy comparison to stack (KT-1899)

This commit is contained in:
Dmitry Jemerov
2012-06-02 18:19:27 +02:00
parent f909745d1b
commit 12498e30eb
5 changed files with 23 additions and 3 deletions
@@ -2922,7 +2922,7 @@ If finally block is present, its last expression is the value of try expression.
}
if(entries.size() == 0) {
v.visitFieldInsn(Opcodes.GETSTATIC, "jet/Tuple0", "INSTANCE", "Ljet/Tuple0;");
return StackValue.onStack(Type.getObjectType("jet/Tuple0"));
return StackValue.onStack(TUPLE0_TYPE);
}
final String className = "jet/Tuple" + entries.size();
@@ -61,6 +61,7 @@ public class JetTypeMapper {
public static final Type JL_CLASS_TYPE = Type.getObjectType("java/lang/Class");
public static final Type ARRAY_GENERIC_TYPE = Type.getType(Object[].class);
public static final Type TUPLE0_TYPE = Type.getObjectType("jet/Tuple0");
private JetStandardLibrary standardLibrary;
public BindingContext bindingContext;
@@ -203,8 +203,9 @@ public abstract class StackValue {
v.pop2();
}
else if (type.getSort() != Type.VOID && this.type.getSort() == Type.VOID) {
if(type.getSort() == Type.OBJECT)
v.visitFieldInsn(Opcodes.GETSTATIC, "jet/Tuple0", "INSTANCE", "Ljet/Tuple0;");
if(type.getSort() == Type.OBJECT) {
putTuple0Instance(v);
}
else if(type == Type.LONG_TYPE)
v.lconst(0);
else if(type == Type.FLOAT_TYPE)
@@ -243,6 +244,10 @@ public abstract class StackValue {
}
}
protected static void putTuple0Instance(InstructionAdapter v) {
v.visitFieldInsn(Opcodes.GETSTATIC, "jet/Tuple0", "INSTANCE", "Ljet/Tuple0;");
}
protected void putAsBoolean(InstructionAdapter v) {
Label ifTrue = new Label();
Label end = new Label();
@@ -393,6 +398,10 @@ public abstract class StackValue {
if (type == Type.VOID_TYPE) {
return;
}
if (type.equals(JetTypeMapper.TUPLE0_TYPE)) {
putTuple0Instance(v);
return;
}
if (type != Type.BOOLEAN_TYPE) {
throw new UnsupportedOperationException("don't know how to put a compare as a non-boolean type " + type);
}
@@ -0,0 +1,5 @@
fun box(): String {
if (1 != 0) {
}
return "OK"
}
@@ -336,4 +336,9 @@ public class ControlStructuresTest extends CodegenTestCase {
createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS);
blackBoxFile("regressions/kt2147.kt");
}
public void testIfDummy() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS);
blackBoxFile("regressions/kt1899.kt");
}
}