Fix inference when captured type is used as a lambda parameter type

Use lower approximation bound to obtain acceptable types for lambda parameters
those types depend on captured type

 #KT-12238 Fixed
 #KT-10627 Fixed
This commit is contained in:
Denis Zharkov
2016-09-19 19:58:55 +03:00
parent cb32bc97dd
commit 4431c6ad02
7 changed files with 104 additions and 1 deletions
@@ -254,7 +254,14 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes
val argumentExpression = valueArgument.getArgumentExpression() ?: return
val effectiveExpectedType = getEffectiveExpectedType(valueParameterDescriptor, valueArgument)
var expectedType = constraintSystem.build().currentSubstitutor.substitute(effectiveExpectedType, Variance.INVARIANT)
val currentSubstitutor = constraintSystem.build().currentSubstitutor
val newSubstitution = object : DelegatedTypeSubstitution(currentSubstitutor.substitution) {
override fun approximateContravariantCapturedTypes() = true
}
var expectedType = newSubstitution.buildSubstitutor().substitute(effectiveExpectedType, Variance.IN_VARIANCE)
if (expectedType == null || TypeUtils.isDontCarePlaceholder(expectedType)) {
expectedType = argumentTypeResolver.getShapeTypeOfFunctionLiteral(functionLiteral, context.scope, context.trace, false)
}