[FIR] Check compatibility of equality call between IT by component of each type

^KT-48113 Fixed
This commit is contained in:
Dmitriy Novozhilov
2021-08-27 11:00:32 +03:00
committed by TeamCityServer
parent 5bdfa14a37
commit 67dd23354c
2 changed files with 9 additions and 11 deletions
@@ -1,5 +1,7 @@
// FULL_JDK
// ISSUE: KT-48113
fun collapse(path: String) {
val result = (path as java.lang.String).replace("123", "456")
if (<!EQUALITY_NOT_APPLICABLE_WARNING!>result !== path<!>) {}
}
if (result !== path) {}
}
@@ -64,21 +64,17 @@ internal object ConeTypeCompatibilityChecker {
}
fun ConeInferenceContext.isCompatible(a: ConeKotlinType, b: ConeKotlinType): Compatibility {
val aUnwrap = unwrap(a)
val bUnwrap = unwrap(b)
if (aUnwrap.containsAll(bUnwrap) || bUnwrap.containsAll(aUnwrap)) {
return Compatibility.COMPATIBLE
if (a is ConeIntersectionType) {
return a.intersectedTypes.minOf { isCompatible(it, b) }
}
if (b is ConeIntersectionType) {
return b.intersectedTypes.minOf { isCompatible(a, it) }
}
val intersectionType = intersectTypesOrNull(listOf(a, b)) as? ConeIntersectionType ?: return Compatibility.COMPATIBLE
return intersectionType.intersectedTypes.areCompatible(this)
}
private fun unwrap(type: ConeKotlinType): Collection<ConeKotlinType> = when (type) {
is ConeIntersectionType -> type.intersectedTypes
else -> listOf(type)
}
private fun Collection<ConeKotlinType>.areCompatible(ctx: ConeInferenceContext): Compatibility {
// If all types are nullable, then `null` makes the given types compatible.
if (all { with(ctx) { it.isNullableType() } }) return Compatibility.COMPATIBLE