[NI] Don't return resulting call if return type has uninferred types

This commit is contained in:
Mikhail Zarechenskiy
2019-04-25 12:47:15 +03:00
parent db4ca059bd
commit ac0a1d984f
16 changed files with 40 additions and 26 deletions
@@ -19,13 +19,14 @@ package org.jetbrains.kotlin.resolve.calls.results;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.config.LanguageFeature;
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency;
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext;
import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.tower.KotlinToResolvedCallTransformerKt;
import org.jetbrains.kotlin.resolve.calls.tower.NewResolvedCallImpl;
import org.jetbrains.kotlin.resolve.calls.tower.NewVariableAsFunctionResolvedCallImpl;
import org.jetbrains.kotlin.types.KotlinType;
import java.util.Collection;
@@ -56,15 +57,21 @@ public class OverloadResolutionResultsUtil {
) {
if (results.isSingleResult() && context.contextDependency == ContextDependency.INDEPENDENT) {
ResolvedCall<D> resultingCall = results.getResultingCall();
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) {
if (!((MutableResolvedCall<D>) resultingCall).hasInferredReturnType()) {
return null;
}
NewResolvedCallImpl<?> newResolvedCall;
if (resultingCall instanceof NewVariableAsFunctionResolvedCallImpl) {
newResolvedCall = ((NewVariableAsFunctionResolvedCallImpl) resultingCall).getFunctionCall();
}
else {
if (KotlinToResolvedCallTransformerKt.isNewNotCompleted(resultingCall)) {
else if (resultingCall instanceof NewResolvedCallImpl) {
newResolvedCall = (NewResolvedCallImpl<?>) resultingCall;
} else {
newResolvedCall = null;
}
if (newResolvedCall != null) {
if (!KotlinToResolvedCallTransformerKt.hasInferredReturnType(newResolvedCall)) {
return null;
}
} else if (!((MutableResolvedCall<D>) resultingCall).hasInferredReturnType()) {
return null;
}
}
return results.isSingleResult() ? results.getResultingCall() : null;
@@ -764,3 +764,10 @@ fun ResolvedCall<*>.isNewNotCompleted(): Boolean {
}
return false
}
fun NewResolvedCallImpl<*>.hasInferredReturnType(): Boolean {
if (isNewNotCompleted()) return false
val returnType = this.resultingDescriptor.returnType ?: return false
return !returnType.contains { ErrorUtils.isUninferredParameter(it) }
}