diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java index f75f6872237..4fdcc60cb2a 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java @@ -527,10 +527,6 @@ public class AsmUtil { return StackValue.cmp(opToken, leftType, left, right); } - if (opToken == JetTokens.EQEQEQ || opToken == JetTokens.EXCLEQEQEQ) { - return StackValue.cmp(opToken, leftType, left, right); - } - return StackValue.operation(Type.BOOLEAN_TYPE, new Function1() { @Override public Unit invoke(InstructionAdapter v) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 803919fbdf9..3d9f943c061 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -3056,7 +3056,16 @@ public class ExpressionCodegen extends JetVisitor implem rightType = boxType(rightType); } - return genEqualsForExpressionsOnStack(opToken, genLazy(left, leftType), genLazy(right, rightType)); + StackValue leftValue = genLazy(left, leftType); + StackValue rightValue = genLazy(right, rightType); + + if (opToken == JetTokens.EQEQEQ || opToken == JetTokens.EXCLEQEQEQ) { + // TODO: always casting to the type of the left operand in case of primitives looks wrong + Type operandType = isPrimitive(leftType) ? leftType : OBJECT_TYPE; + return StackValue.cmp(opToken, operandType, leftValue, rightValue); + } + + return genEqualsForExpressionsOnStack(opToken, leftValue, rightValue); } private boolean isIntZero(JetExpression expr, Type exprType) { diff --git a/compiler/testData/codegen/box/binaryOp/kt6747_identityEquals.kt b/compiler/testData/codegen/box/binaryOp/kt6747_identityEquals.kt new file mode 100644 index 00000000000..d1b8600619b --- /dev/null +++ b/compiler/testData/codegen/box/binaryOp/kt6747_identityEquals.kt @@ -0,0 +1,10 @@ +class Test { + fun check(a: Any?): String { + if (this === a) return "Fail 1" + if (!(this !== a)) return "Fail 2" + if (this.identityEquals(a)) return "Fail 3" + return "OK" + } +} + +fun box(): String = Test().check("String") diff --git a/compiler/testData/codegen/box/platformTypes/primitives/udentityEquals.kt b/compiler/testData/codegen/box/platformTypes/primitives/identityEquals.kt similarity index 99% rename from compiler/testData/codegen/box/platformTypes/primitives/udentityEquals.kt rename to compiler/testData/codegen/box/platformTypes/primitives/identityEquals.kt index f7b239824a7..ae9aefb1c64 100644 --- a/compiler/testData/codegen/box/platformTypes/primitives/udentityEquals.kt +++ b/compiler/testData/codegen/box/platformTypes/primitives/identityEquals.kt @@ -17,4 +17,4 @@ fun box(): String { if (!y2) return "Fail (y2): $y" return "OK" -} \ No newline at end of file +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index a621b5c076f..98bc8cd568a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -282,6 +282,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt6747_identityEquals.kt") + public void testKt6747_identityEquals() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/binaryOp/kt6747_identityEquals.kt"); + doTest(fileName); + } + @TestMetadata("longOverflow.kt") public void testLongOverflow() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/binaryOp/longOverflow.kt"); @@ -5276,6 +5282,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("identityEquals.kt") + public void testIdentityEquals() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/platformTypes/primitives/identityEquals.kt"); + doTest(fileName); + } + @TestMetadata("inc.kt") public void testInc() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/platformTypes/primitives/inc.kt"); @@ -5342,12 +5354,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } - @TestMetadata("udentityEquals.kt") - public void testUdentityEquals() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/platformTypes/primitives/udentityEquals.kt"); - doTest(fileName); - } - @TestMetadata("unaryMinus.kt") public void testUnaryMinus() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/platformTypes/primitives/unaryMinus.kt");