[NI] Map vararg to Array if it's resolved against type variable

While this behavior is questionable, it's consistent with OI and can
 be changed in future

 #KT-36201 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-01-28 12:58:17 +03:00
parent 35f6810b58
commit e3b6104489
11 changed files with 111 additions and 4 deletions
@@ -170,7 +170,8 @@ class CallableReferencesCandidateFactory(
val callComponents: KotlinCallComponents,
val scopeTower: ImplicitScopeTower,
val compatibilityChecker: ((ConstraintSystemOperation) -> Unit) -> Unit,
val expectedType: UnwrappedType?
val expectedType: UnwrappedType?,
private val csBuilder: ConstraintSystemOperation
) : CandidateFactory<CallableReferenceCandidate> {
fun createCallableProcessor(explicitReceiver: DetailedReceiver?) =
@@ -333,7 +334,9 @@ class CallableReferencesCandidateFactory(
return when (varargMappingState) {
VarargMappingState.UNMAPPED -> {
if (KotlinBuiltIns.isArrayOrPrimitiveArray(expectedParameterType)) {
if (KotlinBuiltIns.isArrayOrPrimitiveArray(expectedParameterType) ||
csBuilder.isTypeVariable(expectedParameterType)
) {
val arrayType = builtins.getPrimitiveArrayKotlinTypeByPrimitiveKotlinType(elementType)
?: builtins.getArrayType(Variance.OUT_VARIANCE, elementType)
arrayType to VarargMappingState.MAPPED_WITH_ARRAY
@@ -78,7 +78,7 @@ class CallableReferenceResolver(
val expectedType = resolvedAtom.expectedType?.let { (csBuilder.buildCurrentSubstitutor() as NewTypeSubstitutor).safeSubstitute(it) }
val scopeTower = callComponents.statelessCallbacks.getScopeTowerForCallableReferenceArgument(argument)
val candidates = runRHSResolution(scopeTower, argument, expectedType) { checkCallableReference ->
val candidates = runRHSResolution(scopeTower, argument, expectedType, csBuilder) { checkCallableReference ->
csBuilder.runTransaction { checkCallableReference(this); false }
}
@@ -133,9 +133,12 @@ class CallableReferenceResolver(
scopeTower: ImplicitScopeTower,
callableReference: CallableReferenceKotlinCallArgument,
expectedType: UnwrappedType?, // this type can have not fixed type variable inside
csBuilder: ConstraintSystemBuilder,
compatibilityChecker: ((ConstraintSystemOperation) -> Unit) -> Unit // you can run anything throw this operation and all this operation will be rolled back
): Set<CallableReferenceCandidate> {
val factory = CallableReferencesCandidateFactory(callableReference, callComponents, scopeTower, compatibilityChecker, expectedType)
val factory = CallableReferencesCandidateFactory(
callableReference, callComponents, scopeTower, compatibilityChecker, expectedType, csBuilder
)
val processor = createCallableReferenceProcessor(factory)
val candidates = towerResolver.runResolve(scopeTower, processor, useOrder = true, name = callableReference.rhsName)
return callableReferenceOverloadConflictResolver.chooseMaximallySpecificCandidates(