From cde54d59bd5906b3a100ac5e0a9c4cfb68c5b117 Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Mon, 2 Jan 2012 09:49:04 +0200 Subject: [PATCH] KT-877 - wrong codegen for unary plus --- .../org/jetbrains/jet/codegen/intrinsics/UnaryPlus.java | 7 ++++++- compiler/testData/codegen/regressions/kt877.jet | 9 +++++++++ .../org/jetbrains/jet/codegen/PrimitiveTypesTest.java | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/regressions/kt877.jet diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryPlus.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryPlus.java index 2405ef3d8aa..92a8f99f297 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryPlus.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryPlus.java @@ -21,7 +21,12 @@ public class UnaryPlus implements IntrinsicMethod { if(nullable) { expectedType = JetTypeMapper.unboxType(expectedType); } - receiver.put(expectedType, v); + if(receiver != null && receiver != StackValue.none()) + receiver.put(expectedType, v); + else { + assert arguments != null; + codegen.gen(arguments.get(0), expectedType); + } return StackValue.onStack(expectedType); } } diff --git a/compiler/testData/codegen/regressions/kt877.jet b/compiler/testData/codegen/regressions/kt877.jet new file mode 100644 index 00000000000..094c5f88fae --- /dev/null +++ b/compiler/testData/codegen/regressions/kt877.jet @@ -0,0 +1,9 @@ +fun box() : String { + var a : Int = -1 + if((+a) != -1) return "fail 1" + a = 1 + if((+a) != 1) return "fail 2" + if((+-1) != -1) return "fail 3" + if((-+a) != -1) return "fail 4" + return "OK" +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java index 0c7ad33b70b..72beaf1807f 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java @@ -351,4 +351,8 @@ public class PrimitiveTypesTest extends CodegenTestCase { public void testKt757 () { blackBoxFile("regressions/kt757.jet"); } + + public void testKt877 () { + blackBoxFile("regressions/kt877.jet"); + } }