From 34a0b0dcd4f1acb0401d2c7affaa7f28c23534d3 Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Sat, 4 Aug 2012 12:46:49 +0300 Subject: [PATCH] KT-2334 partly fix: boolean to object coercion --- .../src/org/jetbrains/jet/codegen/StackValue.java | 6 ++++-- compiler/testData/codegen/regressions/kt2334.kt | 13 +++++++++++++ .../tests/org/jetbrains/jet/codegen/StdlibTest.java | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/codegen/regressions/kt2334.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java index 4469028acef..726fbc6518a 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java @@ -447,7 +447,7 @@ public abstract class StackValue { putTuple0Instance(v); return; } - if (type != Type.BOOLEAN_TYPE && type.equals(JetTypeMapper.TYPE_OBJECT) && type.equals(JetTypeMapper.JL_BOOLEAN_TYPE)) { + if (type != Type.BOOLEAN_TYPE && !type.equals(JetTypeMapper.TYPE_OBJECT) && !type.equals(JetTypeMapper.JL_BOOLEAN_TYPE)) { throw new UnsupportedOperationException("don't know how to put a compare as a non-boolean type " + type); } putAsBoolean(v); @@ -534,10 +534,12 @@ public abstract class StackValue { myOperand.put(type, v); // the operand will remove itself from the stack if needed return; } - if (type != Type.BOOLEAN_TYPE) { + if (type != Type.BOOLEAN_TYPE && !type.equals(JetTypeMapper.TYPE_OBJECT) && !type.equals(JetTypeMapper.JL_BOOLEAN_TYPE)) { 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); } @Override diff --git a/compiler/testData/codegen/regressions/kt2334.kt b/compiler/testData/codegen/regressions/kt2334.kt new file mode 100644 index 00000000000..2a1eb0a4b1a --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2334.kt @@ -0,0 +1,13 @@ +import kotlin.test.* +import org.junit.Test as test + +public class Test { + test fun f(): Unit { + assertEquals(true, !false) + } +} + +fun box() : String { + Test().f() + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java index 826ed5fb3c4..ad64b9943c5 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java @@ -337,6 +337,10 @@ public class StdlibTest extends CodegenTestCase { blackBoxFile("regressions/kt1800.kt"); } + public void testKt2334() { + blackBoxFile("regressions/kt2334.kt"); + } + public void testUptoDownto() { blackBoxFile("uptoDownto.kt"); }