Avoid type approximation on generating equality constraints

#KT-37389 fixed
This commit is contained in:
Ilya Chernikov
2020-03-16 18:01:38 +01:00
parent 950ab01596
commit da1009eb2c
@@ -119,12 +119,9 @@ class ConstraintIncorporator(
otherVariable: TypeVariableMarker, otherVariable: TypeVariableMarker,
otherConstraint: Constraint otherConstraint: Constraint
) { ) {
val typeWithSubstitution = when (otherConstraint.kind) {
val baseConstraintType = baseConstraint.type
val typeForApproximation = when (otherConstraint.kind) {
ConstraintKind.EQUALITY -> { ConstraintKind.EQUALITY -> {
baseConstraintType.substitute(this, otherVariable, otherConstraint.type) baseConstraint.type.substitute(this, otherVariable, otherConstraint.type)
} }
ConstraintKind.UPPER -> { ConstraintKind.UPPER -> {
val temporaryCapturedType = createCapturedType( val temporaryCapturedType = createCapturedType(
@@ -133,7 +130,7 @@ class ConstraintIncorporator(
null, null,
CaptureStatus.FOR_INCORPORATION CaptureStatus.FOR_INCORPORATION
) )
baseConstraintType.substitute(this, otherVariable, temporaryCapturedType) baseConstraint.type.substitute(this, otherVariable, temporaryCapturedType)
} }
ConstraintKind.LOWER -> { ConstraintKind.LOWER -> {
val temporaryCapturedType = createCapturedType( val temporaryCapturedType = createCapturedType(
@@ -142,18 +139,23 @@ class ConstraintIncorporator(
otherConstraint.type, otherConstraint.type,
CaptureStatus.FOR_INCORPORATION CaptureStatus.FOR_INCORPORATION
) )
baseConstraint.type.substitute(this, otherVariable, temporaryCapturedType)
baseConstraintType.substitute(this, otherVariable, temporaryCapturedType)
} }
} }
if (baseConstraint.kind != ConstraintKind.UPPER) { when (baseConstraint.kind) {
val generatedConstraintType = approximateCapturedTypes(typeForApproximation, toSuper = false) ConstraintKind.EQUALITY -> {
addNewConstraint(targetVariable, baseConstraint, otherVariable, otherConstraint, generatedConstraintType, isSubtype = true) addNewConstraint(targetVariable, baseConstraint, otherVariable, otherConstraint, typeWithSubstitution, isSubtype = true)
} addNewConstraint(targetVariable, baseConstraint, otherVariable, otherConstraint, typeWithSubstitution, isSubtype = false)
if (baseConstraint.kind != ConstraintKind.LOWER) { }
val generatedConstraintType = approximateCapturedTypes(typeForApproximation, toSuper = true) ConstraintKind.UPPER -> {
addNewConstraint(targetVariable, baseConstraint, otherVariable, otherConstraint, generatedConstraintType, isSubtype = false) val generatedConstraintType = approximateCapturedTypes(typeWithSubstitution, toSuper = true)
addNewConstraint(targetVariable, baseConstraint, otherVariable, otherConstraint, generatedConstraintType, isSubtype = false)
}
ConstraintKind.LOWER -> {
val generatedConstraintType = approximateCapturedTypes(typeWithSubstitution, toSuper = false)
addNewConstraint(targetVariable, baseConstraint, otherVariable, otherConstraint, generatedConstraintType, isSubtype = true)
}
} }
} }