Introduce language feature for NI, remove old setting

This commit is contained in:
Mikhail Zarechenskiy
2017-10-20 15:46:33 +03:00
parent 27e7f13335
commit 73b4e24d54
21 changed files with 80 additions and 82 deletions
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.diagnostics.Errors.*
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.resolve.BindingContext.*
import org.jetbrains.kotlin.resolve.calls.USE_NEW_INFERENCE
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getCalleeExpressionIfAny
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
@@ -529,7 +528,7 @@ class DelegatedPropertyResolver(
trace: BindingTrace,
dataFlowInfo: DataFlowInfo
): KotlinType? {
if (!USE_NEW_INFERENCE) return null
if (!languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) return null
val traceToResolveConventionMethods = TemporaryBindingTrace.create(trace, "Trace to resolve delegated property convention methods")
@@ -672,7 +672,7 @@ public class DescriptorResolver {
BindingTrace trace,
@NotNull LexicalScope scope
) {
UnwrappedType approximatedType = typeApproximator.approximateDeclarationType(type, true);
UnwrappedType approximatedType = typeApproximator.approximateDeclarationType(type, true, languageVersionSettings);
VariableDescriptor variableDescriptor = new LocalVariableDescriptor(
scope.getOwnerDescriptor(),
annotationResolver.resolveAnnotationsWithArguments(scope, parameter.getModifierList(), trace),
@@ -1157,7 +1157,7 @@ public class DescriptorResolver {
PreliminaryDeclarationVisitor.Companion.createForDeclaration(function, trace, languageVersionSettings);
KotlinType type = expressionTypingServices.getBodyExpressionType(trace, scope, dataFlowInfo, function, functionDescriptor);
KotlinType publicType = transformAnonymousTypeIfNeeded(functionDescriptor, function, type, trace);
UnwrappedType approximatedType = typeApproximator.approximateDeclarationType(publicType, false);
UnwrappedType approximatedType = typeApproximator.approximateDeclarationType(publicType, false, languageVersionSettings);
KotlinType sanitizedType = declarationReturnTypeSanitizer.sanitizeReturnType(approximatedType, wrappedTypeFactory, trace, languageVersionSettings);
functionsTypingVisitor.checkTypesForReturnStatements(function, trace, sanitizedType);
return sanitizedType;
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -161,5 +161,6 @@ class VariableTypeAndInitializerResolver(
return declarationReturnTypeSanitizer.sanitizeReturnType(approximatedType, wrappedTypeFactory, trace, languageVersionSettings)
}
private fun approximateType(type: KotlinType, local: Boolean): UnwrappedType = typeApproximator.approximateDeclarationType(type, local)
private fun approximateType(type: KotlinType, local: Boolean): UnwrappedType =
typeApproximator.approximateDeclarationType(type, local, expressionTypingServices.languageVersionSettings)
}
@@ -263,8 +263,7 @@ public class ArgumentTypeResolver {
if (overloadResolutionResults == null) return null;
if (isSingleAndPossibleTransformToSuccess(overloadResolutionResults)) {
ResolvedCall<?> resolvedCall =
OverloadResolutionResultsUtil.getResultingCall(overloadResolutionResults, context.contextDependency);
ResolvedCall<?> resolvedCall = OverloadResolutionResultsUtil.getResultingCall(overloadResolutionResults, context);
if (resolvedCall == null) return null;
return DoubleColonExpressionResolver.Companion.createKCallableTypeForReference(
@@ -20,6 +20,7 @@ import com.intellij.lang.ASTNode
import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
@@ -90,8 +91,10 @@ class CallExpressionResolver(
): Pair<Boolean, ResolvedCall<FunctionDescriptor>?> {
val results = callResolver.resolveFunctionCall(BasicCallResolutionContext.create(
context, call, checkArguments, DataFlowInfoForArgumentsImpl(initialDataFlowInfoForArguments, call)))
return if (!results.isNothing) Pair(true, OverloadResolutionResultsUtil.getResultingCall(results, context.contextDependency))
else Pair(false, null)
return if (!results.isNothing)
Pair(true, OverloadResolutionResultsUtil.getResultingCall(results, context))
else
Pair(false, null)
}
private fun getVariableType(
@@ -281,7 +284,7 @@ class CallExpressionResolver(
}
else when (resolutionResult.resultCode) {
NAME_NOT_FOUND, CANDIDATES_WITH_WRONG_RECEIVER -> false
else -> !USE_NEW_INFERENCE || resolutionResult.isSuccess
else -> !context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference) || resolutionResult.isSuccess
}
}
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.FunctionTypesKt;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.config.LanguageFeature;
import org.jetbrains.kotlin.config.LanguageVersionSettings;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
@@ -571,12 +572,13 @@ public class CallResolver {
Call call = context.call;
tracing.bindCall(context.trace, call);
if (KotlinResolutionConfigurationKt.getUSE_NEW_INFERENCE() && (resolutionTask.resolutionKind.getKotlinCallKind() != KotlinCallKind.UNSUPPORTED)) {
boolean newInferenceEnabled = languageVersionSettings.supportsFeature(LanguageFeature.NewInference);
if (newInferenceEnabled && (resolutionTask.resolutionKind.getKotlinCallKind() != KotlinCallKind.UNSUPPORTED)) {
assert resolutionTask.name != null;
return PSICallResolver.runResolutionAndInference(context, resolutionTask.name, resolutionTask.resolutionKind, tracing);
}
if (KotlinResolutionConfigurationKt.getUSE_NEW_INFERENCE() && resolutionTask.resolutionKind instanceof NewResolutionOldInference.ResolutionKind.GivenCandidates) {
if (newInferenceEnabled && resolutionTask.resolutionKind instanceof NewResolutionOldInference.ResolutionKind.GivenCandidates) {
assert resolutionTask.givenCandidates != null;
return PSICallResolver.runResolutionAndInferenceForGivenCandidates(context, resolutionTask.givenCandidates, tracing);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,9 +19,10 @@ 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.KotlinResolutionConfigurationKt;
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;
@@ -41,20 +42,20 @@ public class OverloadResolutionResultsUtil {
@Nullable
public static <D extends CallableDescriptor> KotlinType getResultingType(
@NotNull OverloadResolutionResults<D> results,
@NotNull ContextDependency contextDependency
@NotNull ResolutionContext<?> context
) {
ResolvedCall<D> resultingCall = getResultingCall(results, contextDependency);
ResolvedCall<D> resultingCall = getResultingCall(results, context);
return resultingCall != null ? resultingCall.getResultingDescriptor().getReturnType() : null;
}
@Nullable
public static <D extends CallableDescriptor> ResolvedCall<D> getResultingCall(
@NotNull OverloadResolutionResults<D> results,
@NotNull ContextDependency contextDependency
@NotNull ResolutionContext<?> context
) {
if (results.isSingleResult() && contextDependency == ContextDependency.INDEPENDENT) {
if (results.isSingleResult() && context.contextDependency == ContextDependency.INDEPENDENT) {
ResolvedCall<D> resultingCall = results.getResultingCall();
if (!KotlinResolutionConfigurationKt.getUSE_NEW_INFERENCE()) {
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) {
if (!((MutableResolvedCall<D>) resultingCall).hasInferredReturnType()) {
return null;
}
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver
import org.jetbrains.kotlin.resolve.calls.DiagnosticReporterByTrackingStrategy
import org.jetbrains.kotlin.resolve.calls.REPORT_MISSING_NEW_INFERENCE_DIAGNOSTIC
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.getEffectiveExpectedType
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.callUtil.isFakeElement
@@ -72,6 +71,11 @@ class KotlinToResolvedCallTransformer(
private val additionalDiagnosticReporter: AdditionalDiagnosticReporter
) {
companion object {
private val REPORT_MISSING_NEW_INFERENCE_DIAGNOSTIC
get() = false
}
fun <D : CallableDescriptor> onlyTransform(
resolvedCallAtom: ResolvedCallAtom
): ResolvedCall<D> = transformToResolvedCall(resolvedCallAtom, null)
@@ -316,6 +316,9 @@ class NewResolutionOldInference(
override val lexicalScope: LexicalScope get() = resolutionContext.scope
override val isDebuggerContext: Boolean get() = resolutionContext.isDebuggerContext
override val isNewInferenceEnabled: Boolean
get() = resolutionContext.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)
}
internal class MyCandidate(
@@ -282,6 +282,7 @@ class PSICallResolver(
override val syntheticScopes: SyntheticScopes get() = this@PSICallResolver.syntheticScopes
override val isDebuggerContext: Boolean get() = context.isDebuggerContext
override val isNewInferenceEnabled: Boolean get() = context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)
override val lexicalScope: LexicalScope get() = context.scope
private val cache = HashMap<ReceiverParameterDescriptor, ReceiverValueWithSmartCastInfo>()
@@ -45,7 +45,6 @@ import org.jetbrains.kotlin.resolve.*;
import org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilsKt;
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver;
import org.jetbrains.kotlin.resolve.calls.CallExpressionResolver;
import org.jetbrains.kotlin.resolve.calls.KotlinResolutionConfigurationKt;
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
import org.jetbrains.kotlin.resolve.calls.checkers.*;
import org.jetbrains.kotlin.resolve.calls.model.DataFlowInfoForArgumentsImpl;
@@ -857,7 +856,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
baseTypeInfo = baseTypeInfo.replaceDataFlowInfo(dataFlowInfo.disequate(value, DataFlowValue.nullValue(components.builtIns),
components.languageVersionSettings));
}
KotlinType resultingType = KotlinResolutionConfigurationKt.getUSE_NEW_INFERENCE()
KotlinType resultingType = components.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)
? resolvedCall.getResultingDescriptor().getReturnType()
: TypeUtils.makeNotNullable(baseType);
if (context.contextDependency == DEPENDENT) {
@@ -1371,7 +1370,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
CallMaker.makeCall(callElement, receiver, null, operationSign, Collections.singletonList(leftArgument)),
operationSign,
OperatorNameConventions.CONTAINS);
KotlinType containsType = OverloadResolutionResultsUtil.getResultingType(resolutionResult, context.contextDependency);
KotlinType containsType = OverloadResolutionResultsUtil.getResultingType(resolutionResult, context);
ensureBooleanResult(operationSign, OperatorNameConventions.CONTAINS, containsType, context);
if (left != null) {
@@ -1517,7 +1516,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
typeInfo = typeInfo.replaceDataFlowInfo(resolutionResults.getResultingCall().getDataFlowInfoForArguments().getResultInfo());
}
return typeInfo.replaceType(OverloadResolutionResultsUtil.getResultingType(resolutionResults, context.contextDependency));
return typeInfo.replaceType(OverloadResolutionResultsUtil.getResultingType(resolutionResults, context));
}
@Override
@@ -524,7 +524,7 @@ class DoubleColonExpressionResolver(
): KotlinType? {
val descriptor =
if (resolutionResults != null && !resolutionResults.isNothing) {
val resolvedCall = OverloadResolutionResultsUtil.getResultingCall(resolutionResults, context.contextDependency)
val resolvedCall = OverloadResolutionResultsUtil.getResultingCall(resolutionResults, context)
resolvedCall?.resultingDescriptor ?: return null
}
else {
@@ -20,6 +20,7 @@ import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.config.LanguageFeature;
import org.jetbrains.kotlin.config.LanguageVersionSettings;
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
@@ -27,7 +28,6 @@ import org.jetbrains.kotlin.descriptors.ScriptDescriptor;
import org.jetbrains.kotlin.lexer.KtTokens;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.resolve.*;
import org.jetbrains.kotlin.resolve.calls.KotlinResolutionConfigurationKt;
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency;
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
@@ -336,7 +336,7 @@ public class ExpressionTypingServices {
}
ContextDependency dependency = context.contextDependency;
if (KotlinResolutionConfigurationKt.getUSE_NEW_INFERENCE()) {
if (getLanguageVersionSettings().supportsFeature(LanguageFeature.NewInference)) {
dependency = ContextDependency.INDEPENDENT;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -226,8 +226,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
context.replaceTraceAndCache(temporaryForAssignmentOperation).replaceScope(scope),
receiver, expression, name
);
KotlinType assignmentOperationType = OverloadResolutionResultsUtil.getResultingType(assignmentOperationDescriptors,
context.contextDependency);
KotlinType assignmentOperationType = OverloadResolutionResultsUtil.getResultingType(assignmentOperationDescriptors, context);
OverloadResolutionResults<FunctionDescriptor> binaryOperationDescriptors;
KotlinType binaryOperationType;
@@ -243,7 +242,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
receiver, expression, counterpartName
);
binaryOperationType = OverloadResolutionResultsUtil.getResultingType(binaryOperationDescriptors, context.contextDependency);
binaryOperationType = OverloadResolutionResultsUtil.getResultingType(binaryOperationDescriptors, context);
}
else {
binaryOperationDescriptors = OverloadResolutionResultsImpl.nameNotFound();
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.types.expressions
import com.google.common.collect.Lists
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.builtins.*
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
@@ -36,7 +37,6 @@ import org.jetbrains.kotlin.resolve.BindingContext.EXPECTED_RETURN_TYPE
import org.jetbrains.kotlin.resolve.BindingContextUtils
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil
import org.jetbrains.kotlin.resolve.calls.USE_NEW_INFERENCE
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
import org.jetbrains.kotlin.resolve.checkers.UnderscoreChecker
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
@@ -132,7 +132,7 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
val resultType = functionDescriptor.createFunctionType(suspendFunctionTypeExpected)
if (USE_NEW_INFERENCE && functionalTypeExpected)
if (components.languageVersionSettings.supportsFeature(LanguageFeature.NewInference) && functionalTypeExpected)
createTypeInfo(resultType, context)
else
components.dataFlowAnalyzer.createCheckedTypeInfo(resultType, context, function)
@@ -242,7 +242,7 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
val newInferenceLambdaInfo = context.trace[BindingContext.NEW_INFERENCE_LAMBDA_INFO, expression.functionLiteral]
// i.e. this lambda isn't call arguments
if (newInferenceLambdaInfo == null && USE_NEW_INFERENCE) {
if (newInferenceLambdaInfo == null && context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) {
newContext = newContext.replaceContextDependency(ContextDependency.INDEPENDENT)
}
@@ -1,23 +0,0 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.resolve.calls
val USE_NEW_INFERENCE
get() = false
val REPORT_MISSING_NEW_INFERENCE_DIAGNOSTIC
get() = false
@@ -42,6 +42,8 @@ interface ImplicitScopeTower {
val location: LookupLocation
val isDebuggerContext: Boolean
val isNewInferenceEnabled: Boolean
}
interface ScopeTowerLevel {
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.calls.tower
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.calls.USE_NEW_INFERENCE
import org.jetbrains.kotlin.resolve.calls.smartcasts.getReceiverValueWithSmartCast
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForTypeAliasObject
@@ -65,15 +64,13 @@ internal abstract class AbstractScopeTowerLevel(
}
if (dispatchReceiverSmartCastType != null) diagnostics.add(UsedSmartCastForDispatchReceiver(dispatchReceiverSmartCastType))
if (!USE_NEW_INFERENCE) {
val shouldSkipVisibilityCheck = scopeTower.isDebuggerContext
if (!shouldSkipVisibilityCheck) {
Visibilities.findInvisibleMember(
getReceiverValueWithSmartCast(dispatchReceiver?.receiverValue, dispatchReceiverSmartCastType),
descriptor,
scopeTower.lexicalScope.ownerDescriptor
)?.let { diagnostics.add(VisibilityError(it)) }
}
val shouldSkipVisibilityCheck = scopeTower.isDebuggerContext || scopeTower.isNewInferenceEnabled
if (!shouldSkipVisibilityCheck) {
Visibilities.findInvisibleMember(
getReceiverValueWithSmartCast(dispatchReceiver?.receiverValue, dispatchReceiverSmartCastType),
descriptor,
scopeTower.lexicalScope.ownerDescriptor
)?.let { diagnostics.add(VisibilityError(it)) }
}
}
return CandidateWithBoundDispatchReceiverImpl(dispatchReceiver, descriptor, diagnostics)
@@ -89,6 +86,7 @@ internal class MemberScopeTowerLevel(
): AbstractScopeTowerLevel(scopeTower) {
private val syntheticScopes = scopeTower.syntheticScopes
private val isNewInferenceEnabled = scopeTower.isNewInferenceEnabled
private fun collectMembers(
getMembers: ResolutionScope.(KotlinType?) -> Collection<CallableDescriptor>
@@ -137,7 +135,7 @@ internal class MemberScopeTowerLevel(
* And we should chose get(Int): String.
*/
private fun CallableDescriptor.approximateCapturedTypes(): CallableDescriptor {
if (!USE_NEW_INFERENCE) return this
if (!isNewInferenceEnabled) return this
val approximator = TypeApproximator()
val wrappedSubstitution = object : TypeSubstitution() {
@@ -16,8 +16,9 @@
package org.jetbrains.kotlin.types
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
import org.jetbrains.kotlin.resolve.calls.USE_NEW_INFERENCE
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstructor
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration.IntersectionStrategy.*
import org.jetbrains.kotlin.types.checker.*
@@ -80,8 +81,8 @@ class TypeApproximator {
private val referenceApproximateToSuperType = this::approximateSimpleToSuperType
private val referenceApproximateToSubType = this::approximateSimpleToSubType
fun approximateDeclarationType(baseType: KotlinType, local: Boolean): UnwrappedType {
if (!USE_NEW_INFERENCE) return baseType.unwrap()
fun approximateDeclarationType(baseType: KotlinType, local: Boolean, languageVersionSettings: LanguageVersionSettings): UnwrappedType {
if (!languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) return baseType.unwrap()
val configuration = if (local) TypeApproximatorConfiguration.LocalDeclaration else TypeApproximatorConfiguration.PublicDeclaration
return approximateToSuperType(baseType.unwrap(), configuration) ?: baseType.unwrap()
@@ -49,7 +49,6 @@ import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.platform.JvmBuiltIns
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.calls.USE_NEW_INFERENCE
import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver
@@ -126,7 +125,7 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
}
moduleBindings[testModule] = result.bindingContext
checkAllResolvedCallsAreCompleted(ktFiles, result.bindingContext)
checkAllResolvedCallsAreCompleted(ktFiles, result.bindingContext, languageVersionSettings)
}
// We want to always create a test data file (txt) if it was missing,
@@ -524,7 +523,11 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
setDependencies(this, builtIns.builtInsModule)
}
private fun checkAllResolvedCallsAreCompleted(ktFiles: List<KtFile>, bindingContext: BindingContext) {
private fun checkAllResolvedCallsAreCompleted(
ktFiles: List<KtFile>,
bindingContext: BindingContext,
configuredLanguageVersionSettings: LanguageVersionSettings
) {
if (ktFiles.any { file -> AnalyzingUtils.getSyntaxErrorRanges(file).isNotEmpty() }) return
val resolvedCallsEntries = bindingContext.getSliceContents(BindingContext.RESOLVED_CALL)
@@ -533,16 +536,16 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
val lineAndColumn = DiagnosticUtils.getLineAndColumnInPsiFile(element.containingFile, element.textRange)
if (!USE_NEW_INFERENCE) {
if (!configuredLanguageVersionSettings.supportsFeature(LanguageFeature.NewInference)) {
assertTrue("Resolved call for '${element.text}'$lineAndColumn is not completed",
(resolvedCall as MutableResolvedCall<*>).isCompleted)
}
}
checkResolvedCallsInDiagnostics(bindingContext)
checkResolvedCallsInDiagnostics(bindingContext, configuredLanguageVersionSettings)
}
private fun checkResolvedCallsInDiagnostics(bindingContext: BindingContext) {
private fun checkResolvedCallsInDiagnostics(bindingContext: BindingContext, configuredLanguageVersionSettings: LanguageVersionSettings) {
val diagnosticsStoringResolvedCalls1 = setOf(
OVERLOAD_RESOLUTION_AMBIGUITY, NONE_APPLICABLE, CANNOT_COMPLETE_RESOLVE, UNRESOLVED_REFERENCE_WRONG_RECEIVER,
ASSIGN_OPERATOR_AMBIGUITY, ITERATOR_AMBIGUITY
@@ -554,19 +557,23 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
for (diagnostic in bindingContext.diagnostics) {
when (diagnostic.factory) {
in diagnosticsStoringResolvedCalls1 -> assertResolvedCallsAreCompleted(
diagnostic, DiagnosticFactory.cast(diagnostic, diagnosticsStoringResolvedCalls1).a
diagnostic, DiagnosticFactory.cast(diagnostic, diagnosticsStoringResolvedCalls1).a, configuredLanguageVersionSettings
)
in diagnosticsStoringResolvedCalls2 -> assertResolvedCallsAreCompleted(
diagnostic, DiagnosticFactory.cast(diagnostic, diagnosticsStoringResolvedCalls2).b
diagnostic, DiagnosticFactory.cast(diagnostic, diagnosticsStoringResolvedCalls2).b, configuredLanguageVersionSettings
)
}
}
}
private fun assertResolvedCallsAreCompleted(diagnostic: Diagnostic, resolvedCalls: Collection<ResolvedCall<*>>) {
private fun assertResolvedCallsAreCompleted(
diagnostic: Diagnostic,
resolvedCalls: Collection<ResolvedCall<*>>,
configuredLanguageVersionSettings: LanguageVersionSettings
) {
val element = diagnostic.psiElement
val lineAndColumn = DiagnosticUtils.getLineAndColumnInPsiFile(element.containingFile, element.textRange)
if (USE_NEW_INFERENCE) return
if (configuredLanguageVersionSettings.supportsFeature(LanguageFeature.NewInference)) return
assertTrue("Resolved calls stored in ${diagnostic.factory.name}\nfor '${element.text}'$lineAndColumn are not completed",
resolvedCalls.all { (it as MutableResolvedCall<*>).isCompleted })
@@ -82,6 +82,8 @@ enum class LanguageFeature(
MultiPlatformProjects(sinceVersion = null, defaultState = State.DISABLED),
NewInference(sinceVersion = KOTLIN_1_3, defaultState = State.DISABLED),
;
val presentableName: String