[FE 1.0] Report progressions resolve changing warning while calling Java methods which pass Collection

^KT-51062 Fixed
This commit is contained in:
Victor Petukhov
2022-01-31 18:42:50 +03:00
parent 8f23fc54a4
commit a54c9edaad
9 changed files with 165 additions and 5 deletions
@@ -372,7 +372,7 @@ internal fun List<KotlinCallArgument>.replaceTypes(
internal fun PSIKotlinCall.replaceArguments(
newArguments: List<KotlinCallArgument>,
newReceiverArgument: ReceiverExpressionKotlinCallArgument? = null,
newReceiverArgument: ReceiverKotlinCallArgument? = null,
): PSIKotlinCall = PSIKotlinCallImpl(
callKind, psiCall, tracingStrategy, newReceiverArgument, dispatchReceiverForInvokeExtension, name, typeArguments, newArguments,
externalArgument, startingDataFlowInfo, resultDataFlowInfo, dataFlowInfoForArguments, isForImplicitInvoke
@@ -78,7 +78,7 @@ class PassingProgressionAsCollectionCallChecker(private val kotlinCallResolver:
)
)
}
val newCall = kotlinCall.replaceArguments(newArguments)
val newCall = kotlinCall.replaceArguments(newArguments, kotlinCall.explicitReceiver)
val candidateForCollectionReplacedArgument = kotlinCallResolver.resolveCall(
scopeTower, resolutionCallbacks, newCall, expectedType, context.collectAllCandidates
@@ -107,12 +107,12 @@ class PassingProgressionAsCollectionCallChecker(private val kotlinCallResolver:
} else type
} ?: continue
val cons = alternativeParameterType.constructor
val alternativeParameterTypeConstructor = alternativeParameterType.upperIfFlexible().constructor
if (cons.declarationDescriptor != builtIns.collection && (cons !is IntersectionTypeConstructor || cons.supertypes.none { it.constructor.declarationDescriptor == builtIns.collection })) continue
if (alternativeParameterTypeConstructor.declarationDescriptor != builtIns.collection && (alternativeParameterTypeConstructor !is IntersectionTypeConstructor || alternativeParameterTypeConstructor.supertypes.none { it.constructor.declarationDescriptor == builtIns.collection })) continue
val argumentExpression = argument.psiExpression ?: continue
val initialArgumentType = resolvedCall.candidateDescriptor.valueParameters.getOrNull(i)?.type ?: continue
val initialArgumentType = resolvedCall.candidateDescriptor.valueParameters.getOrNull(i)?.type?.upperIfFlexible() ?: continue
// Iterable initial type is an exception, considered as similar to Collection passing candidate
if (initialArgumentType.constructor.declarationDescriptor == builtIns.iterable) continue