[FE] Support reporting INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION for empty intersection types with type parameters

This commit is contained in:
Victor Petukhov
2022-02-11 14:20:28 +03:00
committed by teamcity
parent c16ae81a48
commit b96708c3e2
26 changed files with 307 additions and 19 deletions
@@ -178,15 +178,25 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
fun KotlinTypeMarker.isFinal(): Boolean
fun Collection<KotlinTypeMarker>.isEmptyIntersection(): Boolean =
any { first ->
any { second ->
fun Collection<KotlinTypeMarker>.isEmptyIntersection(): Boolean {
val expandedTypes = buildSet {
for (type in this@isEmptyIntersection) {
val typeConstructor = type.typeConstructor()
when {
typeConstructor.isClassTypeConstructor() -> add(type)
typeConstructor.isTypeParameterTypeConstructor() -> addAll(typeConstructor.supertypes())
}
}
}.takeIf { it.isNotEmpty() } ?: return false
return expandedTypes.any { first ->
expandedTypes.any { second ->
first !== second &&
first.isFinal() &&
second.typeConstructor().isClassTypeConstructor() &&
!AbstractTypeChecker.isSubtypeOf(this@TypeSystemInferenceExtensionContext, first, second)
}
}
}
fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker
fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker