From a851bb0fffdb33f9857c893c329bd6596b489b8e Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Wed, 23 Mar 2016 17:23:00 +0100 Subject: [PATCH] Fix for KT-11584: Regression in 1.0.1: incorrect comparison of Long! with integer constant #KT-11584 Fixed --- .../jetbrains/kotlin/codegen/ExpressionCodegen.java | 2 +- .../codegen/box/binaryOp/compareWithBoxedLong.kt | 13 +++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/binaryOp/compareWithBoxedLong.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 0888f2aa371..00a0ac9515e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -3138,7 +3138,7 @@ public class ExpressionCodegen extends KtVisitor impleme Type leftType = expressionType(left); Type rightType = expressionType(right); Callable callable = resolveToCallable((FunctionDescriptor) resolvedCall.getResultingDescriptor(), false, resolvedCall); - if (callable instanceof IntrinsicCallable) { + if (isPrimitive(leftType) && isPrimitive(rightType) && callable instanceof IntrinsicCallable) { type = comparisonOperandType(leftType, rightType); leftValue = gen(left); rightValue = gen(right); diff --git a/compiler/testData/codegen/box/binaryOp/compareWithBoxedLong.kt b/compiler/testData/codegen/box/binaryOp/compareWithBoxedLong.kt new file mode 100644 index 00000000000..fdb16449a1a --- /dev/null +++ b/compiler/testData/codegen/box/binaryOp/compareWithBoxedLong.kt @@ -0,0 +1,13 @@ +//FILE: JavaClass.java + +class JavaClass { + public static Long get() { return 2364137526064485012L; } +} + +//FILE: test.kt + +import JavaClass + +fun box(): String { + return if (JavaClass.get() > 0) "OK" else "fail" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 6a205ae670d..f3dd58ec512 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -730,6 +730,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("compareWithBoxedLong.kt") + public void testCompareWithBoxedLong() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/binaryOp/compareWithBoxedLong.kt"); + doTest(fileName); + } + @TestMetadata("divisionByZero.kt") public void testDivisionByZero() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/binaryOp/divisionByZero.kt");