[FE 1.0] Return to the old type intersection emptiness check
This reverts commit 8227c4b603.
#KT-53656 Fixed
This commit is contained in:
+3
-34
@@ -11,11 +11,10 @@ import org.jetbrains.kotlin.types.isDefinitelyEmpty
|
||||
import org.jetbrains.kotlin.types.isPossiblyEmpty
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
|
||||
object EmptyIntersectionTypeChecker {
|
||||
internal object EmptyIntersectionTypeChecker {
|
||||
fun computeEmptyIntersectionEmptiness(
|
||||
context: TypeSystemInferenceExtensionContext,
|
||||
types: Collection<KotlinTypeMarker>,
|
||||
compatibilityModeEnabled: Boolean = false
|
||||
types: Collection<KotlinTypeMarker>
|
||||
): EmptyIntersectionTypeInfo? = with(context) {
|
||||
if (types.isEmpty()) return null
|
||||
|
||||
@@ -35,11 +34,6 @@ object EmptyIntersectionTypeChecker {
|
||||
|
||||
if (!mayCauseEmptyIntersection(secondType)) continue
|
||||
|
||||
if (compatibilityModeEnabled) {
|
||||
val compatibleKind = computeEmptyIntersectionEmptinessCompatible(firstType, secondType)
|
||||
if (compatibleKind != null) return compatibleKind else continue
|
||||
}
|
||||
|
||||
val secondSubstitutedType = secondType.eraseContainingTypeParameters()
|
||||
|
||||
if (!mayCauseEmptyIntersection(secondSubstitutedType) && !mayCauseEmptyIntersection(firstSubstitutedType)) continue
|
||||
@@ -292,31 +286,6 @@ object EmptyIntersectionTypeChecker {
|
||||
val type = argument.getType()
|
||||
return if (type is CapturedTypeMarker) type.typeConstructorProjection() else argument
|
||||
}
|
||||
|
||||
private fun TypeSystemInferenceExtensionContext.computeEmptyIntersectionEmptinessCompatible(
|
||||
firstType: KotlinTypeMarker,
|
||||
secondType: KotlinTypeMarker
|
||||
): EmptyIntersectionTypeInfo? {
|
||||
@Suppress("NAME_SHADOWING")
|
||||
val firstType = firstType.withNullability(false)
|
||||
|
||||
@Suppress("NAME_SHADOWING")
|
||||
val secondType = secondType.withNullability(false)
|
||||
|
||||
val firstErasedType by lazy { firstType.eraseContainingTypeParameters() }
|
||||
val secondErasedType by lazy { secondType.eraseContainingTypeParameters() }
|
||||
|
||||
if (AbstractTypeChecker.areRelatedBySubtyping(this, firstErasedType, secondErasedType))
|
||||
return null
|
||||
|
||||
val canBothHaveSubtypes = firstType.withNullability(false).canHaveSubtypes(AbstractTypeChecker) == true
|
||||
&& secondType.withNullability(false).canHaveSubtypes(AbstractTypeChecker) == true
|
||||
|
||||
if (canBothHaveSubtypes)
|
||||
return null
|
||||
|
||||
return EmptyIntersectionTypeInfo(EmptyIntersectionTypeKind.COMPATIBLE, firstErasedType, secondErasedType)
|
||||
}
|
||||
}
|
||||
|
||||
class EmptyIntersectionTypeInfo(val kind: EmptyIntersectionTypeKind, vararg val casingTypes: KotlinTypeMarker)
|
||||
class EmptyIntersectionTypeInfo(val kind: EmptyIntersectionTypeKind, vararg val casingTypes: KotlinTypeMarker)
|
||||
@@ -9,11 +9,7 @@ enum class EmptyIntersectionTypeKind(val description: String) {
|
||||
MULTIPLE_CLASSES("multiple incompatible classes"),
|
||||
INCOMPATIBLE_SUPERTYPES("incompatible supertypes"),
|
||||
INCOMPATIBLE_TYPE_ARGUMENTS("incompatible type arguments"),
|
||||
SINGLE_FINAL_CLASS("final class and interface"),
|
||||
|
||||
// This kind corresponds to migrated logic from old TypeIntersector
|
||||
// Now it's used for determining types compatibility for is/as/equality checks
|
||||
COMPATIBLE("")
|
||||
SINGLE_FINAL_CLASS("final class and interface")
|
||||
}
|
||||
|
||||
fun EmptyIntersectionTypeKind.isDefinitelyEmpty(): Boolean =
|
||||
|
||||
@@ -179,8 +179,6 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
|
||||
fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker
|
||||
fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker
|
||||
|
||||
fun KotlinTypeMarker.canHaveSubtypes(typeChecker: AbstractTypeChecker): Boolean?
|
||||
|
||||
fun SimpleTypeMarker.replaceArguments(newArguments: List<TypeArgumentMarker>): SimpleTypeMarker
|
||||
fun SimpleTypeMarker.replaceArguments(replacement: (TypeArgumentMarker) -> TypeArgumentMarker): SimpleTypeMarker
|
||||
|
||||
|
||||
Reference in New Issue
Block a user