EmptyIntersectionTypeChecker: minor refactoring
This commit is contained in:
committed by
Space Team
parent
caf511acc5
commit
7fed0c64f0
+22
-20
@@ -91,19 +91,7 @@ internal object EmptyIntersectionTypeChecker {
|
|||||||
return EmptyIntersectionTypeInfo(EmptyIntersectionTypeKind.MULTIPLE_CLASSES, firstType, secondType)
|
return EmptyIntersectionTypeInfo(EmptyIntersectionTypeKind.MULTIPLE_CLASSES, firstType, secondType)
|
||||||
}
|
}
|
||||||
|
|
||||||
val firstSuperTypeWithSecondConstructor = AbstractTypeChecker.findCorrespondingSupertypes(
|
|
||||||
typeCheckerState, firstType.lowerBoundIfFlexible(), secondTypeConstructor
|
|
||||||
).singleOrNull()
|
|
||||||
val secondSuperTypeByFirstConstructor = AbstractTypeChecker.findCorrespondingSupertypes(
|
|
||||||
typeCheckerState, secondType.lowerBoundIfFlexible(), firstTypeConstructor
|
|
||||||
).singleOrNull()
|
|
||||||
|
|
||||||
val atLeastOneInterface = firstTypeConstructor.isInterface() || secondTypeConstructor.isInterface()
|
val atLeastOneInterface = firstTypeConstructor.isInterface() || secondTypeConstructor.isInterface()
|
||||||
|
|
||||||
// Two classes can't have a common subtype if neither is a subtype of another
|
|
||||||
if (firstSuperTypeWithSecondConstructor == null && secondSuperTypeByFirstConstructor == null && !atLeastOneInterface)
|
|
||||||
return EmptyIntersectionTypeInfo(EmptyIntersectionTypeKind.MULTIPLE_CLASSES, firstType, secondType)
|
|
||||||
|
|
||||||
if (atLeastOneInterface) {
|
if (atLeastOneInterface) {
|
||||||
val incompatibleSupertypes = getIncompatibleSuperTypes(firstType, secondType)
|
val incompatibleSupertypes = getIncompatibleSuperTypes(firstType, secondType)
|
||||||
if (incompatibleSupertypes != null) {
|
if (incompatibleSupertypes != null) {
|
||||||
@@ -111,15 +99,15 @@ internal object EmptyIntersectionTypeChecker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstSuperTypeWithSecondConstructor == null || secondSuperTypeByFirstConstructor == null) {
|
val firstSuperTypeWithSecondConstructor = AbstractTypeChecker.findCorrespondingSupertypes(
|
||||||
// don't have incompatible supertypes so can have a common subtype only if all types are interfaces
|
typeCheckerState, firstType.lowerBoundIfFlexible(), secondTypeConstructor
|
||||||
if (firstTypeConstructor.isFinalClassConstructor() || secondTypeConstructor.isFinalClassConstructor()) {
|
).singleOrNull()
|
||||||
possibleEmptyIntersectionKind =
|
val secondSuperTypeByFirstConstructor = AbstractTypeChecker.findCorrespondingSupertypes(
|
||||||
EmptyIntersectionTypeInfo(EmptyIntersectionTypeKind.SINGLE_FINAL_CLASS, firstType, secondType)
|
typeCheckerState, secondType.lowerBoundIfFlexible(), firstTypeConstructor
|
||||||
}
|
).singleOrNull()
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
|
when {
|
||||||
|
firstSuperTypeWithSecondConstructor != null && secondSuperTypeByFirstConstructor != null -> {
|
||||||
val argumentsIntersectionKind =
|
val argumentsIntersectionKind =
|
||||||
computeByCheckingTypeArguments(firstSuperTypeWithSecondConstructor, secondSuperTypeByFirstConstructor) ?: continue
|
computeByCheckingTypeArguments(firstSuperTypeWithSecondConstructor, secondSuperTypeByFirstConstructor) ?: continue
|
||||||
|
|
||||||
@@ -129,6 +117,20 @@ internal object EmptyIntersectionTypeChecker {
|
|||||||
if (possibleEmptyIntersectionKind == null && argumentsIntersectionKind.kind.isPossiblyEmpty())
|
if (possibleEmptyIntersectionKind == null && argumentsIntersectionKind.kind.isPossiblyEmpty())
|
||||||
possibleEmptyIntersectionKind = argumentsIntersectionKind
|
possibleEmptyIntersectionKind = argumentsIntersectionKind
|
||||||
}
|
}
|
||||||
|
firstSuperTypeWithSecondConstructor == null && secondSuperTypeByFirstConstructor == null && !atLeastOneInterface -> {
|
||||||
|
// Two classes can't have a common subtype if neither is a subtype of another
|
||||||
|
return EmptyIntersectionTypeInfo(EmptyIntersectionTypeKind.MULTIPLE_CLASSES, firstType, secondType)
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
// don't have incompatible supertypes so can have a common subtype only if all types are interfaces
|
||||||
|
if (firstTypeConstructor.isFinalClassConstructor() || secondTypeConstructor.isFinalClassConstructor()) {
|
||||||
|
possibleEmptyIntersectionKind =
|
||||||
|
EmptyIntersectionTypeInfo(EmptyIntersectionTypeKind.SINGLE_FINAL_CLASS, firstType, secondType)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return possibleEmptyIntersectionKind
|
return possibleEmptyIntersectionKind
|
||||||
|
|||||||
Reference in New Issue
Block a user