From 4ef1af7d120313f551ca0425f95fcb66fa9755f2 Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Mon, 16 Dec 2013 14:04:18 +0400 Subject: [PATCH] Cast unary intrinsics to expected type --- .../org/jetbrains/jet/codegen/intrinsics/UnaryMinus.java | 4 +++- .../testData/codegen/box/unaryOp/callWithCommonType.kt | 8 ++++++++ .../codegen/generated/BlackBoxCodegenTestGenerated.java | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/unaryOp/callWithCommonType.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryMinus.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryMinus.java index 726fc4c695e..945f94197e2 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryMinus.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryMinus.java @@ -53,6 +53,8 @@ public class UnaryMinus implements IntrinsicMethod { else { receiver.put(operandType, v); } - return StackValue.onStack(genNegate(returnType, v)); + Type negatedValue = genNegate(returnType, v); + StackValue.coerce(negatedValue, returnType, v); + return StackValue.onStack(returnType); } } diff --git a/compiler/testData/codegen/box/unaryOp/callWithCommonType.kt b/compiler/testData/codegen/box/unaryOp/callWithCommonType.kt new file mode 100644 index 00000000000..e97ae934efe --- /dev/null +++ b/compiler/testData/codegen/box/unaryOp/callWithCommonType.kt @@ -0,0 +1,8 @@ +fun box(): String { + if (!foo(1.toByte())) return "fail 1" + if (!foo(-1.toByte())) return "fail 2" + + return "OK" +} + +fun foo(p: Any) = p is Byte \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java index e479d72785f..3ef54068bfe 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -4845,6 +4845,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest("compiler/testData/codegen/box/unaryOp/callNullable.kt"); } + @TestMetadata("callWithCommonType.kt") + public void testCallWithCommonType() throws Exception { + doTest("compiler/testData/codegen/box/unaryOp/callWithCommonType.kt"); + } + @TestMetadata("intrinsic.kt") public void testIntrinsic() throws Exception { doTest("compiler/testData/codegen/box/unaryOp/intrinsic.kt");