[NI] Approximate intersection type in type argument to star if it's necessary

#KT-32196 Fixed
This commit is contained in:
Dmitriy Novozhilov
2019-12-19 14:27:58 +03:00
parent 26f7bf1c21
commit e730965bc5
15 changed files with 288 additions and 1 deletions
@@ -510,6 +510,24 @@ abstract class AbstractTypeApproximator(val ctx: TypeSystemInferenceExtensionCon
}
} ?: continue@loop
if (
conf.intersection != ALLOWED &&
effectiveVariance == TypeVariance.OUT &&
argumentType.typeConstructor().isIntersection()
) {
var shouldReplaceWithStar = false
for (upperBoundIndex in 0 until parameter.upperBoundCount()) {
if (!AbstractTypeChecker.isSubtypeOf(ctx, approximatedArgument, parameter.getUpperBound(upperBoundIndex))) {
shouldReplaceWithStar = true
break
}
}
if (shouldReplaceWithStar) {
newArguments[index] = createStarProjection(parameter)
continue@loop
}
}
if (parameter.getVariance() == TypeVariance.INV) {
newArguments[index] = createTypeArgument(approximatedArgument, effectiveVariance)
} else {