Consider intersection with ILT subtype of ILT
This commit is contained in:
@@ -235,28 +235,40 @@ object AbstractTypeChecker {
|
||||
return isSubtypeOfForSingleClassifierType(subType.lowerBoundIfFlexible(), superType.upperBoundIfFlexible())
|
||||
}
|
||||
|
||||
private fun AbstractTypeCheckerContext.checkSubtypeForIntegerLiteralType(subType: SimpleTypeMarker, superType: SimpleTypeMarker): Boolean? {
|
||||
private fun AbstractTypeCheckerContext.checkSubtypeForIntegerLiteralType(
|
||||
subType: SimpleTypeMarker,
|
||||
superType: SimpleTypeMarker
|
||||
): Boolean? {
|
||||
if (!subType.isIntegerLiteralType() && !superType.isIntegerLiteralType()) return null
|
||||
|
||||
fun typeInIntegerLiteralType(integerLiteralType: SimpleTypeMarker, type: SimpleTypeMarker, checkSupertypes: Boolean): Boolean =
|
||||
fun isTypeInIntegerLiteralType(integerLiteralType: SimpleTypeMarker, type: SimpleTypeMarker, checkSupertypes: Boolean): Boolean =
|
||||
integerLiteralType.possibleIntegerTypes().any { possibleType ->
|
||||
(possibleType.typeConstructor() == type.typeConstructor()) || (checkSupertypes && isSubtypeOf(this, type, possibleType))
|
||||
}
|
||||
|
||||
fun isIntegerLiteralTypeInIntersectionComponents(type: SimpleTypeMarker): Boolean {
|
||||
val typeConstructor = type.typeConstructor()
|
||||
|
||||
return typeConstructor is IntersectionTypeConstructorMarker
|
||||
&& typeConstructor.supertypes().any { it.asSimpleType()?.isIntegerLiteralType() == true }
|
||||
}
|
||||
|
||||
when {
|
||||
subType.isIntegerLiteralType() && superType.isIntegerLiteralType() -> {
|
||||
return true
|
||||
}
|
||||
|
||||
subType.isIntegerLiteralType() -> {
|
||||
if (typeInIntegerLiteralType(subType, superType, checkSupertypes = false)) {
|
||||
if (isTypeInIntegerLiteralType(subType, superType, checkSupertypes = false)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
superType.isIntegerLiteralType() -> {
|
||||
// Here we also have to check supertypes for intersection types: { Int & String } <: IntegerLiteralTypes
|
||||
if (typeInIntegerLiteralType(superType, subType, checkSupertypes = true)) {
|
||||
if (isIntegerLiteralTypeInIntersectionComponents(subType)
|
||||
|| isTypeInIntegerLiteralType(superType, subType, checkSupertypes = true)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user