diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index fcf2b259c01..99fd1c63a4b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -1110,13 +1110,13 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { if (KotlinBuiltIns.isPrimitiveType(leftType)) { context.trace.report(DEPRECATED_IDENTITY_EQUALS.on(expression, leftType, rightType)); } - else if (InlineClassesUtilsKt.isInlineClassType(leftType)) { - context.trace.report(FORBIDDEN_IDENTITY_EQUALS.on(expression, leftType, rightType)); - } } else if (isIdentityComparedWithImplicitBoxing(leftType, rightType) || isIdentityComparedWithImplicitBoxing(rightType, leftType)) { context.trace.report(IMPLICIT_BOXING_IN_IDENTITY_EQUALS.on(expression, leftType, rightType)); } + if (InlineClassesUtilsKt.isInlineClassType(leftType) || InlineClassesUtilsKt.isInlineClassType(rightType)) { + context.trace.report(FORBIDDEN_IDENTITY_EQUALS.on(expression, leftType, rightType)); + } } private static boolean isIdentityComparedWithImplicitBoxing(KotlinType leftType, KotlinType rightType) { diff --git a/compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.fir.kt index b4e920e64a8..24566925dc7 100644 --- a/compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.fir.kt +++ b/compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.fir.kt @@ -12,4 +12,11 @@ fun test(f1: Foo, f2: Foo, b1: Bar, fn1: Foo?, fn2: Foo?) { val c1 = fn1 === fn2 || fn1 !== fn2 val c2 = f1 === fn1 || f1 !== fn1 val c3 = b1 === fn1 || b1 !== fn1 + + val any = Any() + + val d1 = any === f1 || any !== f1 + val d2 = f1 === any || f1 !== any + val d3 = any === fn1 || any !== fn1 + val d4 = fn1 === any || fn1 !== any } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.kt b/compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.kt index 9f7ed6e3eb9..82ee455bb16 100644 --- a/compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.kt +++ b/compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.kt @@ -7,9 +7,16 @@ inline class Bar(val y: String) fun test(f1: Foo, f2: Foo, b1: Bar, fn1: Foo?, fn2: Foo?) { val a1 = f1 === f2 || f1 !== f2 val a2 = f1 === f1 - val a3 = f1 === b1 || f1 !== b1 + val a3 = f1 === b1 || f1 !== b1 val c1 = fn1 === fn2 || fn1 !== fn2 - val c2 = f1 === fn1 || f1 !== fn1 - val c3 = b1 === fn1 || b1 !== fn1 + val c2 = f1 === fn1 || f1 !== fn1 + val c3 = b1 === fn1 || b1 !== fn1 + + val any = Any() + + val d1 = any === f1 || any !== f1 + val d2 = f1 === any || f1 !== any + val d3 = any === fn1 || any !== fn1 + val d4 = fn1 === any || fn1 !== any } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/valueClasses/identityComparisonWithValueClasses.fir.kt b/compiler/testData/diagnostics/tests/valueClasses/identityComparisonWithValueClasses.fir.kt index 7adb195d541..dd27c6493d6 100644 --- a/compiler/testData/diagnostics/tests/valueClasses/identityComparisonWithValueClasses.fir.kt +++ b/compiler/testData/diagnostics/tests/valueClasses/identityComparisonWithValueClasses.fir.kt @@ -18,4 +18,11 @@ fun test(f1: Foo, f2: Foo, b1: Bar, fn1: Foo?, fn2: Foo?) { val c1 = fn1 === fn2 || fn1 !== fn2 val c2 = f1 === fn1 || f1 !== fn1 val c3 = b1 === fn1 || b1 !== fn1 + + val any = Any() + + val d1 = any === f1 || any !== f1 + val d2 = f1 === any || f1 !== any + val d3 = any === fn1 || any !== fn1 + val d4 = fn1 === any || fn1 !== any } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/valueClasses/identityComparisonWithValueClasses.kt b/compiler/testData/diagnostics/tests/valueClasses/identityComparisonWithValueClasses.kt index dff2b4db257..070d5e588e1 100644 --- a/compiler/testData/diagnostics/tests/valueClasses/identityComparisonWithValueClasses.kt +++ b/compiler/testData/diagnostics/tests/valueClasses/identityComparisonWithValueClasses.kt @@ -13,9 +13,16 @@ value class Bar(val y: String) fun test(f1: Foo, f2: Foo, b1: Bar, fn1: Foo?, fn2: Foo?) { val a1 = f1 === f2 || f1 !== f2 val a2 = f1 === f1 - val a3 = f1 === b1 || f1 !== b1 + val a3 = f1 === b1 || f1 !== b1 val c1 = fn1 === fn2 || fn1 !== fn2 - val c2 = f1 === fn1 || f1 !== fn1 - val c3 = b1 === fn1 || b1 !== fn1 + val c2 = f1 === fn1 || f1 !== fn1 + val c3 = b1 === fn1 || b1 !== fn1 + + val any = Any() + + val d1 = any === f1 || any !== f1 + val d2 = f1 === any || f1 !== any + val d3 = any === fn1 || any !== fn1 + val d4 = fn1 === any || fn1 !== any } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithUnsignedTypes/forbiddenEqualsOnUnsignedTypes.kt b/compiler/testData/diagnostics/testsWithUnsignedTypes/forbiddenEqualsOnUnsignedTypes.kt index fe73b5e18cc..30c4dbbe163 100644 --- a/compiler/testData/diagnostics/testsWithUnsignedTypes/forbiddenEqualsOnUnsignedTypes.kt +++ b/compiler/testData/diagnostics/testsWithUnsignedTypes/forbiddenEqualsOnUnsignedTypes.kt @@ -11,7 +11,7 @@ fun test( val ui = ui1 === ui2 || ui1 !== ui2 val ul = ul1 === ul2 || ul1 !== ul2 - val u = ub1 === ul1 + val u = ub1 === ul1 val a1 = 1u === 2u || 1u !== 2u val a2 = 0xFFFF_FFFF_FFFF_FFFFu === 0xFFFF_FFFF_FFFF_FFFFu