提交 b03966e8 编写于 作者: D Dmitry Jemerov

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

上级 33f0a3ce
......@@ -72,8 +72,8 @@ public abstract class StackValue {
}
public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) {
if (this.type == Type.BOOLEAN_TYPE) {
put(Type.BOOLEAN_TYPE, v);
put(this.type, v);
coerce(Type.BOOLEAN_TYPE, v);
if (jumpIfFalse) {
v.ifeq(label);
}
......@@ -81,10 +81,6 @@ public abstract class StackValue {
v.ifne(label);
}
}
else {
throw new UnsupportedOperationException("can't generate a cond jump for a non-boolean value");
}
}
public static StackValue local(int index, Type type) {
return new Local(index, type);
......
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);
blackBoxFile("regressions/kt1441.kt");
}
public void testKt2147() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS);
blackBoxFile("regressions/kt2147.kt");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册