Avoid type approximation on generating equality constraints
#KT-37389 fixed
This commit is contained in:
+17
-15
@@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user