From 5ecedcbb16f78ef8f0ab29b84a22fd88bb9482fc Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Wed, 19 Apr 2023 10:02:49 +0300 Subject: [PATCH] [FIR] Ensure K2 doesn't report `Int? === String?` --- .../equalityCompatibilityCommonCases.fir.kt | 24 +++++++++++++++++++ .../equalityCompatibilityCommonCases.kt | 24 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/compiler/testData/diagnostics/testsWithStdLib/equalityCompatibilityCommonCases.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/equalityCompatibilityCommonCases.fir.kt index dfa99aefcaf..603e4a09686 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/equalityCompatibilityCommonCases.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/equalityCompatibilityCommonCases.fir.kt @@ -72,3 +72,27 @@ fun incompatibleEnumComparisonSmartCast(c: Any?, e: Any?) { c == e } } + +fun incompatibleIdentityRegardlessNullability(a: Int?, b: String?) { + a == b + a === b +} + +fun incompatibleIdentityRegardlessNullabilitySmartCast(a: Any?, b: Any?) { + if (a is Int? && b is String?) { + a == b + a === b + } +} + +fun incompatibleIdentityRegardlessNullabilityWithValueClasses(c: C?, d: D?) { + c == d + c === d +} + +fun incompatibleIdentityRegardlessNullabilityWithValueClassesSmartCast(c: Any?, d: Any?) { + if (c is C? && d is D?) { + c == d + c === d + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/equalityCompatibilityCommonCases.kt b/compiler/testData/diagnostics/testsWithStdLib/equalityCompatibilityCommonCases.kt index 563ceff1f78..642896c4767 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/equalityCompatibilityCommonCases.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/equalityCompatibilityCommonCases.kt @@ -72,3 +72,27 @@ fun incompatibleEnumComparisonSmartCast(c: Any?, e: Any?) { c == e } } + +fun incompatibleIdentityRegardlessNullability(a: Int?, b: String?) { + a == b + a === b +} + +fun incompatibleIdentityRegardlessNullabilitySmartCast(a: Any?, b: Any?) { + if (a is Int? && b is String?) { + a == b + a === b + } +} + +fun incompatibleIdentityRegardlessNullabilityWithValueClasses(c: C?, d: D?) { + c == d + c === d +} + +fun incompatibleIdentityRegardlessNullabilityWithValueClassesSmartCast(c: Any?, d: Any?) { + if (c is C? && d is D?) { + c == d + c === d + } +}