diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt index c31634a2c8e..c50d762b9d4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt @@ -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") diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java index 2c26cd6e7d3..9bdaf28dc86 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java @@ -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; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt index 095101ccc02..dfd41fcbce2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeAndInitializerResolver.kt @@ -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) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java index 92e4d7e8fcc..e0a6c2c5850 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java @@ -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( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.kt index 9fdd434d701..708758b65e3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.kt @@ -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?> { 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 } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java index 7f641533f32..d634859d680 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java @@ -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); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/OverloadResolutionResultsUtil.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/OverloadResolutionResultsUtil.java index 7b04a546c49..2972567dd25 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/OverloadResolutionResultsUtil.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/OverloadResolutionResultsUtil.java @@ -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 KotlinType getResultingType( @NotNull OverloadResolutionResults results, - @NotNull ContextDependency contextDependency + @NotNull ResolutionContext context ) { - ResolvedCall resultingCall = getResultingCall(results, contextDependency); + ResolvedCall resultingCall = getResultingCall(results, context); return resultingCall != null ? resultingCall.getResultingDescriptor().getReturnType() : null; } @Nullable public static ResolvedCall getResultingCall( @NotNull OverloadResolutionResults results, - @NotNull ContextDependency contextDependency + @NotNull ResolutionContext context ) { - if (results.isSingleResult() && contextDependency == ContextDependency.INDEPENDENT) { + if (results.isSingleResult() && context.contextDependency == ContextDependency.INDEPENDENT) { ResolvedCall resultingCall = results.getResultingCall(); - if (!KotlinResolutionConfigurationKt.getUSE_NEW_INFERENCE()) { + if (!context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) { if (!((MutableResolvedCall) resultingCall).hasInferredReturnType()) { return null; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt index 3835ae68f04..5f6d3783933 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt @@ -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 onlyTransform( resolvedCallAtom: ResolvedCallAtom ): ResolvedCall = transformToResolvedCall(resolvedCallAtom, null) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt index 630d6c8e292..e452e8fcee5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt @@ -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( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt index aa3a0df1ee3..4b79c28a735 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt @@ -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() diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index 3e53cd209d8..195fcd57bf8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -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 diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt index a794b4e57af..1f74bf6b609 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt @@ -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 { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java index 3f47ebe313a..5178722d4cc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java @@ -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; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java index 7a4d60edbbe..310689519e1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java @@ -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 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(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt index 3936ca7220e..8647ab17abf 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt @@ -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) } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinResolutionConfiguration.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinResolutionConfiguration.kt deleted file mode 100644 index a15491e5205..00000000000 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinResolutionConfiguration.kt +++ /dev/null @@ -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 diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt index 4838ce435ac..ed15100ebc6 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt @@ -42,6 +42,8 @@ interface ImplicitScopeTower { val location: LookupLocation val isDebuggerContext: Boolean + + val isNewInferenceEnabled: Boolean } interface ScopeTowerLevel { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt index ad87add0171..12444d28bc7 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt @@ -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 @@ -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() { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt b/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt index 61bce7f1da4..c3402ab9f33 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt @@ -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() diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTest.kt index a4cb15e6921..a1670c3d058 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsTest.kt @@ -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, bindingContext: BindingContext) { + private fun checkAllResolvedCallsAreCompleted( + ktFiles: List, + 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>) { + private fun assertResolvedCallsAreCompleted( + diagnostic: Diagnostic, + resolvedCalls: Collection>, + 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 }) diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index f01005467d6..04051bc3917 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -82,6 +82,8 @@ enum class LanguageFeature( MultiPlatformProjects(sinceVersion = null, defaultState = State.DISABLED), + NewInference(sinceVersion = KOTLIN_1_3, defaultState = State.DISABLED), + ; val presentableName: String