diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java index fee9715f6446f6ec719f7d6cc696e70a482a796f..854096100c462067386d877fc5e362adb7a1d0b7 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java @@ -72,17 +72,13 @@ public abstract class StackValue { } public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) { - if (this.type == Type.BOOLEAN_TYPE) { - put(Type.BOOLEAN_TYPE, v); - if (jumpIfFalse) { - v.ifeq(label); - } - else { - v.ifne(label); - } + put(this.type, v); + coerce(Type.BOOLEAN_TYPE, v); + if (jumpIfFalse) { + v.ifeq(label); } else { - throw new UnsupportedOperationException("can't generate a cond jump for a non-boolean value"); + v.ifne(label); } } diff --git a/compiler/testData/codegen/regressions/kt2147.kt b/compiler/testData/codegen/regressions/kt2147.kt new file mode 100644 index 0000000000000000000000000000000000000000..df664fb16ef2f58826beee168aea9a3aab6fae47 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2147.kt @@ -0,0 +1,9 @@ +class Foo { + fun isOk() = true +} + +fun box(): String { + val foo: Foo? = Foo() + if (foo?.isOk()!!) return "OK" + return "fail" +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java b/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java index 3bf9fadee39e3c42f10194de541afdaaea3f30c3..a73000c174fa8a2808c9aa1307600ae9084e7c45 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java @@ -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"); + } }