[NI] Fix special case of captured type handling in subtyping
Given the subtyping constraint X <: CapturedType(in Y) we should check only X <: Y if X contains type variables.
This commit is contained in:
committed by
Mikhail Zarechenskiy
parent
26cc08be65
commit
9fa3bce73a
+2
-2
@@ -29,8 +29,8 @@ abstract class TypeCheckerContextForConstraintSystem : TypeCheckerContext(errorT
|
||||
abstract fun addUpperConstraint(typeVariable: TypeConstructor, superType: UnwrappedType)
|
||||
abstract fun addLowerConstraint(typeVariable: TypeConstructor, subType: UnwrappedType)
|
||||
|
||||
override fun allowSubtypeViaLowerTypeForCapturedType(subType: SimpleType, superType: NewCapturedType) =
|
||||
!subType.contains { it.anyBound(this::isMyTypeVariable) }
|
||||
override fun shouldCheckOnlyLowerBoundForCapturedType(subType: SimpleType, superType: NewCapturedType) =
|
||||
subType.contains { it.anyBound(this::isMyTypeVariable) }
|
||||
|
||||
/**
|
||||
* todo: possible we should override this method, because otherwise OR in subtyping transformed to AND in constraint system
|
||||
|
||||
@@ -159,12 +159,14 @@ object NewKotlinTypeChecker : KotlinTypeChecker {
|
||||
return StrictEqualityTypeChecker.strictEqualTypes(subType.makeNullableAsSpecified(false), superType.makeNullableAsSpecified(false))
|
||||
}
|
||||
|
||||
if (superType is NewCapturedType &&
|
||||
superType.lowerType != null &&
|
||||
allowSubtypeViaLowerTypeForCapturedType(subType, superType) &&
|
||||
isSubtypeOf(subType, superType.lowerType))
|
||||
{
|
||||
return true
|
||||
if (superType is NewCapturedType && superType.lowerType != null) {
|
||||
val subtypeOfLowerType = isSubtypeOf(subType, superType.lowerType)
|
||||
if (shouldCheckOnlyLowerBoundForCapturedType(subType, superType)) {
|
||||
return subtypeOfLowerType
|
||||
}
|
||||
else if (subtypeOfLowerType) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
(superType.constructor as? IntersectionTypeConstructor)?.let {
|
||||
|
||||
@@ -33,7 +33,7 @@ open class TypeCheckerContext(val errorTypeEqualsToAnything: Boolean, val allowe
|
||||
return a == b
|
||||
}
|
||||
|
||||
open fun allowSubtypeViaLowerTypeForCapturedType(subType: SimpleType, superType: NewCapturedType): Boolean = true
|
||||
open fun shouldCheckOnlyLowerBoundForCapturedType(subType: SimpleType, superType: NewCapturedType): Boolean = false
|
||||
open val sameConstructorPolicy get() = SeveralSupertypesWithSameConstructorPolicy.INTERSECT_ARGUMENTS_AND_CHECK_AGAIN
|
||||
|
||||
internal inline fun <T> runWithArgumentsSettings(subArgument: UnwrappedType, f: TypeCheckerContext.() -> T): T {
|
||||
|
||||
Reference in New Issue
Block a user