From 8e740a3ee4df13ba186ef16706cb7e315f499f99 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 26 Nov 2012 15:37:29 +0400 Subject: [PATCH] Fix .put() for some stack values #KT-3087 Fixed --- .../org/jetbrains/jet/codegen/StackValue.java | 25 ++---------------- .../testData/codegen/regressions/kt3087.kt | 26 +++++++++++++++++++ .../jet/codegen/ControlStructuresTest.java | 5 ++++ 3 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 compiler/testData/codegen/regressions/kt3087.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java index 33d98219573..f8b0bf13800 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java @@ -488,20 +488,8 @@ public abstract class StackValue { @Override public void put(Type type, InstructionAdapter v) { - if (type == Type.VOID_TYPE) { - return; - } - if (type.equals(JET_TUPLE0_TYPE)) { - putTuple0Instance(v); - return; - } - if (type != Type.BOOLEAN_TYPE && !type.equals(OBJECT_TYPE) && !type.equals(getType(Boolean.class))) { - throw new UnsupportedOperationException("don't know how to put a compare as a non-boolean type " + type); - } putAsBoolean(v); - if (type != Type.BOOLEAN_TYPE) { - box(Type.BOOLEAN_TYPE, type, v); - } + coerceTo(type, v); } @Override @@ -580,17 +568,8 @@ public abstract class StackValue { @Override public void put(Type type, InstructionAdapter v) { - if (type == Type.VOID_TYPE) { - myOperand.put(type, v); // the operand will remove itself from the stack if needed - return; - } - if (type != Type.BOOLEAN_TYPE && !type.equals(OBJECT_TYPE) && !type.equals(getType(Boolean.class))) { - throw new UnsupportedOperationException("don't know how to put a compare as a non-boolean type"); - } putAsBoolean(v); - if (type != Type.BOOLEAN_TYPE) { - box(Type.BOOLEAN_TYPE, type, v); - } + coerceTo(type, v); } @Override diff --git a/compiler/testData/codegen/regressions/kt3087.kt b/compiler/testData/codegen/regressions/kt3087.kt new file mode 100644 index 00000000000..5858faa4364 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt3087.kt @@ -0,0 +1,26 @@ +fun putNumberCompareAsUnit() { + if (1 == 1) { + } + else if (1 == 1) { + } +} + +fun putNumberCompareAsVoid() { + if (1 == 1) { + 1 == 1 + } else { + } +} + +fun putInvertAsUnit(b: Boolean) { + if (1 == 1) { + } else if (!b) { + } +} + +fun box(): String { + putNumberCompareAsUnit() + putNumberCompareAsVoid() + putInvertAsUnit(true) + return "OK" +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java b/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java index 82c40ce44fc..34824b3fc51 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java @@ -474,4 +474,9 @@ public class ControlStructuresTest extends CodegenTestCase { createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); blackBoxFile("controlStructures/finallyOnEmptyReturn.kt"); } + + public void testKt3087() { + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + blackBoxFile("regressions/kt3087.kt"); + } }