Hack: do not add trivial constraints (t <: Any?) for constituent types,

otherwise nested calls handling logic in old inference wouldn't work for type alias constructors.
This commit is contained in:
Dmitry Petrov
2016-11-10 12:23:25 +03:00
parent 549ae59562
commit 37eedc3703
7 changed files with 114 additions and 1 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.resolve.calls
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.ReflectionTypes
import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype
import org.jetbrains.kotlin.descriptors.CallableDescriptor
@@ -136,8 +137,13 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes
) {
val substitutedType = substitutedArgument.type
for (upperBound in typeParameter.upperBounds) {
val substitutedUpperBound = boundsSubstitutor.safeSubstitute(upperBound, Variance.INVARIANT)
val substitutedUpperBound = boundsSubstitutor.safeSubstitute(upperBound, Variance.INVARIANT).upperIfFlexible()
val constraintPosition = ValidityConstraintForConstituentType(substitutedType, typeParameter, substitutedUpperBound)
// Do not add extra constraints if upper bound is 'Any?';
// otherwise it will be treated incorrectly in nested calls processing.
if (KotlinBuiltIns.isNullableAny(substitutedUpperBound)) continue
builder.addSubtypeConstraint(substitutedType, substitutedUpperBound, constraintPosition)
}
}