ConeTypeCompatibilityChecker: add temporary workaround for KT-46383

This commit is contained in:
Mikhail Glukhikh
2021-05-05 16:30:15 +03:00
committed by teamcityserver
parent db55a973d4
commit 1936a815e2
3 changed files with 13 additions and 9 deletions
@@ -68,12 +68,16 @@ internal object ConeTypeCompatibilityChecker {
if (all { with(ctx) { it.isNullableType() } }) return Compatibility.COMPATIBLE 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. // Next can simply focus on the type hierarchy and don't need to worry about nullability.
val compatibilityUpperBound = if (this.all { it.isConcreteType() }) { val compatibilityUpperBound = when {
Compatibility.HARD_INCOMPATIBLE all {
} else { it.classId in StandardClassIds.primitiveTypes
// If any type is not concrete, for example, type parameter, we only report warning for incompatible types. This is to stay } -> Compatibility.SOFT_INCOMPATIBLE // TODO: remove after KT-46383 is fixed
// compatible with FE1.0. all {
Compatibility.SOFT_INCOMPATIBLE 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) return ctx.areCompatible(flatMap { it.collectUpperBounds() }.toSet(), emptySet(), compatibilityUpperBound)
} }
@@ -32,7 +32,7 @@ val test_dd = d === d || d !== d
val test_cc = c === c || c !== c val test_cc = c === c || c !== c
// Identity for primitive values of different types (no extra error) // Identity for primitive values of different types (no extra error)
val test_zb = <!EQUALITY_NOT_APPLICABLE!>z === b<!> || <!EQUALITY_NOT_APPLICABLE!>z !== b<!> val test_zb = <!EQUALITY_NOT_APPLICABLE_WARNING!>z === b<!> || <!EQUALITY_NOT_APPLICABLE_WARNING!>z !== b<!>
// Primitive vs nullable // Primitive vs nullable
val test_znz = z === nz || nz === z || z !== nz || nz !== z val test_znz = z === nz || nz === z || z !== nz || nz !== z
@@ -344,7 +344,7 @@ fun case_20(b: Boolean) {
// TESTCASE NUMBER: 21 // TESTCASE NUMBER: 21
fun case_21() { fun case_21() {
if (<!EQUALITY_NOT_APPLICABLE!>EnumClassWithNullableProperty.B.prop_1 !== null is Boolean<!> == <!USELESS_IS_CHECK!>true !is Boolean<!> != true) { if (<!EQUALITY_NOT_APPLICABLE_WARNING!>EnumClassWithNullableProperty.B.prop_1 !== null is Boolean<!> == <!USELESS_IS_CHECK!>true !is Boolean<!> != true) {
EnumClassWithNullableProperty.B.prop_1 EnumClassWithNullableProperty.B.prop_1
EnumClassWithNullableProperty.B.prop_1<!UNSAFE_CALL!>.<!>equals(null) EnumClassWithNullableProperty.B.prop_1<!UNSAFE_CALL!>.<!>equals(null)
EnumClassWithNullableProperty.B.prop_1.propT EnumClassWithNullableProperty.B.prop_1.propT
@@ -376,7 +376,7 @@ fun case_22(a: (() -> Unit)?) {
// TESTCASE NUMBER: 23 // TESTCASE NUMBER: 23
fun case_23(a: ((Float) -> Int?)?, b: Float?) { fun case_23(a: ((Float) -> Int?)?, b: Float?) {
if (<!EQUALITY_NOT_APPLICABLE!>a != null !is Boolean<!> && <!EQUALITY_NOT_APPLICABLE!>b !== null is Boolean<!>) { if (<!EQUALITY_NOT_APPLICABLE!>a != null !is Boolean<!> && <!EQUALITY_NOT_APPLICABLE_WARNING!>b !== null is Boolean<!>) {
val x = <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!><!UNSAFE_IMPLICIT_INVOKE_CALL!>a<!>(<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Float?")!>b<!>)<!> val x = <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!><!UNSAFE_IMPLICIT_INVOKE_CALL!>a<!>(<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Float?")!>b<!>)<!>
if (x != null) { if (x != null) {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int? & kotlin.Int")!>x<!> <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int? & kotlin.Int")!>x<!>