From 1936a815e20f111daed419164b5bb6703eff96b6 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 5 May 2021 16:30:15 +0300 Subject: [PATCH] ConeTypeCompatibilityChecker: add temporary workaround for KT-46383 --- .../checkers/ConeTypeCompatibilityChecker.kt | 16 ++++++++++------ .../IdentityComparisonWithPrimitives.fir.kt | 2 +- .../diagnostics/notLinked/dfa/neg/1.fir.kt | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/ConeTypeCompatibilityChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/ConeTypeCompatibilityChecker.kt index 84fe85636c2..917e5593b6d 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/ConeTypeCompatibilityChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/ConeTypeCompatibilityChecker.kt @@ -68,12 +68,16 @@ internal object ConeTypeCompatibilityChecker { if (all { with(ctx) { it.isNullableType() } }) return Compatibility.COMPATIBLE // Next can simply focus on the type hierarchy and don't need to worry about nullability. - val compatibilityUpperBound = if (this.all { it.isConcreteType() }) { - Compatibility.HARD_INCOMPATIBLE - } else { - // If any type is not concrete, for example, type parameter, we only report warning for incompatible types. This is to stay - // compatible with FE1.0. - Compatibility.SOFT_INCOMPATIBLE + val compatibilityUpperBound = when { + all { + it.classId in StandardClassIds.primitiveTypes + } -> Compatibility.SOFT_INCOMPATIBLE // TODO: remove after KT-46383 is fixed + all { + it.isConcreteType() + } -> Compatibility.HARD_INCOMPATIBLE + // If any type is not concrete, for example, type parameter, we only report warning for incompatible types. + // This is to stay compatible with FE1.0. + else -> Compatibility.SOFT_INCOMPATIBLE } return ctx.areCompatible(flatMap { it.collectUpperBounds() }.toSet(), emptySet(), compatibilityUpperBound) } diff --git a/compiler/testData/diagnostics/tests/IdentityComparisonWithPrimitives.fir.kt b/compiler/testData/diagnostics/tests/IdentityComparisonWithPrimitives.fir.kt index aa5360abff5..c751e6abca2 100644 --- a/compiler/testData/diagnostics/tests/IdentityComparisonWithPrimitives.fir.kt +++ b/compiler/testData/diagnostics/tests/IdentityComparisonWithPrimitives.fir.kt @@ -32,7 +32,7 @@ val test_dd = d === d || d !== d val test_cc = c === c || c !== c // Identity for primitive values of different types (no extra error) -val test_zb = z === b || z !== b +val test_zb = z === b || z !== b // Primitive vs nullable val test_znz = z === nz || nz === z || z !== nz || nz !== z diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt index 9d77fca1e04..5e167596e53 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt @@ -344,7 +344,7 @@ fun case_20(b: Boolean) { // TESTCASE NUMBER: 21 fun case_21() { - if (EnumClassWithNullableProperty.B.prop_1 !== null is Boolean == true !is Boolean != true) { + if (EnumClassWithNullableProperty.B.prop_1 !== null is Boolean == true !is Boolean != true) { EnumClassWithNullableProperty.B.prop_1 EnumClassWithNullableProperty.B.prop_1.equals(null) EnumClassWithNullableProperty.B.prop_1.propT @@ -376,7 +376,7 @@ fun case_22(a: (() -> Unit)?) { // TESTCASE NUMBER: 23 fun case_23(a: ((Float) -> Int?)?, b: Float?) { - if (a != null !is Boolean && b !== null is Boolean) { + if (a != null !is Boolean && b !== null is Boolean) { val x = a(b) if (x != null) { x