From 44ffed95902840af00df357e29e451f91bf0c348 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Mon, 23 Mar 2020 17:12:55 +0100 Subject: [PATCH] Approximate only types substituted with captured types properly fixes #KT-37389 #KT-37389 fixed #KT-37644 fixed --- .../components/ConstraintIncorporator.kt | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt index 29406d5a581..58d654fe9c9 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt @@ -126,17 +126,11 @@ class ConstraintIncorporator( if (needApproximation) approximateCapturedTypes(typeWithSubstitution, toSuper) else typeWithSubstitution } - when (baseConstraint.kind) { - ConstraintKind.EQUALITY -> { - addNewConstraint(targetVariable, baseConstraint, otherVariable, otherConstraint, typeWithSubstitution, isSubtype = false) - addNewConstraint(targetVariable, baseConstraint, otherVariable, otherConstraint, typeWithSubstitution, isSubtype = true) - } - ConstraintKind.UPPER -> { - addNewConstraint(targetVariable, baseConstraint, otherVariable, otherConstraint, prepareType(true), isSubtype = false) - } - ConstraintKind.LOWER -> { - addNewConstraint(targetVariable, baseConstraint, otherVariable, otherConstraint, prepareType(false), isSubtype = true) - } + if (baseConstraint.kind != ConstraintKind.LOWER) { + addNewConstraint(targetVariable, baseConstraint, otherVariable, otherConstraint, prepareType(true), isSubtype = false) + } + if (baseConstraint.kind != ConstraintKind.UPPER) { + addNewConstraint(targetVariable, baseConstraint, otherVariable, otherConstraint, prepareType(false), isSubtype = true) } } @@ -150,7 +144,7 @@ class ConstraintIncorporator( val isOtherCapturedType = otherConstraint.type.isCapturedType() val (type, needApproximation) = when (otherConstraint.kind) { ConstraintKind.EQUALITY -> { - otherConstraint.type to true + otherConstraint.type to false } ConstraintKind.UPPER -> { /*