coerce condition value to Type.BOOLEAN (KT-2147)

This commit is contained in:
Dmitry Jemerov
2012-05-31 13:59:42 +02:00
parent 33f0a3cee0
commit b03966e8d0
3 changed files with 19 additions and 9 deletions
@@ -72,17 +72,13 @@ public abstract class StackValue {
} }
public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) { public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) {
if (this.type == Type.BOOLEAN_TYPE) { put(this.type, v);
put(Type.BOOLEAN_TYPE, v); coerce(Type.BOOLEAN_TYPE, v);
if (jumpIfFalse) { if (jumpIfFalse) {
v.ifeq(label); v.ifeq(label);
}
else {
v.ifne(label);
}
} }
else { else {
throw new UnsupportedOperationException("can't generate a cond jump for a non-boolean value"); v.ifne(label);
} }
} }
@@ -0,0 +1,9 @@
class Foo {
fun isOk() = true
}
fun box(): String {
val foo: Foo? = Foo()
if (foo?.isOk()!!) return "OK"
return "fail"
}
@@ -331,4 +331,9 @@ public class ControlStructuresTest extends CodegenTestCase {
createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS); createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS);
blackBoxFile("regressions/kt1441.kt"); blackBoxFile("regressions/kt1441.kt");
} }
public void testKt2147() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS);
blackBoxFile("regressions/kt2147.kt");
}
} }