[NI] Add missing substitution of known type parameters

Known type parameters appear after inheriting from class with type
parameters. Their substitution matters for inner class constructor,
because without substitution it's parameters will be type checked
against incorrect (original) parameter descriptor with unsubstituted
type parameters.

Skip creation of composite substitutor, if old substitutor is empty.

New substitutors return null in case they don't substitute a type,
but old type substitutors have explicit isEmpty method. Composite
substitutor with empty old substitutor leads to creation
of incorrect descriptor copies.
This commit is contained in:
Pavel Kirpichenkov
2019-11-08 12:47:54 +03:00
parent 3122f2704c
commit b6af13f18d
12 changed files with 220 additions and 9 deletions
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.resolve.calls.context.CallPosition
import org.jetbrains.kotlin.resolve.calls.inference.buildResultingSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.components.composeWith
import org.jetbrains.kotlin.resolve.calls.inference.model.*
import org.jetbrains.kotlin.resolve.calls.inference.substitute
import org.jetbrains.kotlin.resolve.calls.inference.substituteAndApproximateTypes
@@ -728,10 +729,13 @@ class NewResolvedCallImpl<D : CallableDescriptor>(
}
private fun CallableDescriptor.substituteInferredVariablesAndApproximate(substitutor: NewTypeSubstitutor?): CallableDescriptor {
return substitute(resolvedCallAtom.freshVariablesSubstitutor)
.substituteAndApproximateTypes(
substitutor ?: FreshVariableNewTypeSubstitutor.Empty, typeApproximator
)
val inferredTypeVariablesSubstitutor = substitutor ?: FreshVariableNewTypeSubstitutor.Empty
val compositeSubstitutor = resolvedCallAtom.freshVariablesSubstitutor
.composeWith(resolvedCallAtom.knownParametersSubstitutor)
.composeWith(inferredTypeVariablesSubstitutor)
return substituteAndApproximateTypes(compositeSubstitutor, typeApproximator)
}
fun getExpectedTypeForSamConvertedArgument(valueArgument: ValueArgument): UnwrappedType? =