Fix collection literals resolve in gradle-based projects

#KT-19441 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2017-08-06 18:42:09 +02:00
parent b24c1bf06c
commit 0b358fb693
15 changed files with 234 additions and 10 deletions
@@ -74,16 +74,15 @@ class CollectionLiteralResolver(val module: ModuleDescriptor, val callResolver:
): KotlinTypeInfo {
val call = CallMaker.makeCallForCollectionLiteral(expression)
val callName = getArrayFunctionCallName(context.expectedType)
val functionDescriptor = getFunctionDescriptorForCollectionLiteral(expression, callName)
if (functionDescriptor == null) {
val functionDescriptors = getFunctionDescriptorForCollectionLiteral(expression, callName)
if (functionDescriptors.isEmpty()) {
context.trace.report(MISSING_STDLIB.on(
expression, "Collection literal call '$callName()' is unresolved"))
return noTypeInfo(context)
}
val resolutionResults = callResolver.resolveCollectionLiteralCallWithGivenDescriptor(context, expression, call, functionDescriptor)
val resolutionResults = callResolver.resolveCollectionLiteralCallWithGivenDescriptor(context, expression, call, functionDescriptors)
// No single result after resolving one candidate?
if (!resolutionResults.isSingleResult) {
return noTypeInfo(context)
}
@@ -95,9 +94,9 @@ class CollectionLiteralResolver(val module: ModuleDescriptor, val callResolver:
private fun getFunctionDescriptorForCollectionLiteral(
expression: KtCollectionLiteralExpression,
callName: Name
): SimpleFunctionDescriptor? {
): Collection<SimpleFunctionDescriptor> {
val memberScopeOfKotlinPackage = module.getPackage(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME).memberScope
return memberScopeOfKotlinPackage.getContributedFunctions(callName, KotlinLookupLocation(expression)).singleOrNull()
return memberScopeOfKotlinPackage.getContributedFunctions(callName, KotlinLookupLocation(expression))
}
private fun checkSupportsArrayLiterals(expression: KtCollectionLiteralExpression, context: ExpressionTypingContext) {
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve.calls;
import com.intellij.psi.PsiElement;
import kotlin.Pair;
import kotlin.collections.CollectionsKt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.FunctionTypesKt;
@@ -247,14 +248,19 @@ public class CallResolver {
@NotNull ExpressionTypingContext context,
@NotNull KtCollectionLiteralExpression expression,
@NotNull Call call,
@NotNull FunctionDescriptor functionDescriptor
@NotNull Collection<FunctionDescriptor> functionDescriptors
) {
BasicCallResolutionContext callResolutionContext = BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS);
ResolutionCandidate<FunctionDescriptor> candidate = ResolutionCandidate.create(
call, functionDescriptor, null, ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, null);
List<ResolutionCandidate<FunctionDescriptor>> candidates = CollectionsKt.map(functionDescriptors, descriptor ->
ResolutionCandidate.create(
call,
descriptor,
null,
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER,
null));
return computeTasksFromCandidatesAndResolvedCall(
callResolutionContext, Collections.singleton(candidate), TracingStrategyImpl.create(expression, call));
callResolutionContext, candidates, TracingStrategyImpl.create(expression, call));
}
@NotNull