Put removing builder inference restrictions under the compiler flag

This commit is contained in:
Victor Petukhov
2021-05-11 17:15:44 +03:00
parent 5a11450d77
commit 6356b9d501
5 changed files with 27 additions and 1 deletions
@@ -131,6 +131,22 @@ class BuilderInferenceSession(
if (skipCall(callInfo.callResolutionResult)) return
commonCalls.add(callInfo)
val resultingDescriptor = callInfo.resolvedCall.resultingDescriptor
// This check is similar to one for old inference, see getCoroutineInferenceData() function
val checkCall = resultingDescriptor is LocalVariableDescriptor || anyReceiverContainStubType(resultingDescriptor)
if (!checkCall) return
val isApplicableCall = callComponents.statelessCallbacks.isApplicableCallForBuilderInference(
resultingDescriptor,
callComponents.languageVersionSettings
)
if (!isApplicableCall) {
hasInapplicableCall = true
}
}
private fun anyReceiverContainStubType(descriptor: CallableDescriptor): Boolean {
@@ -299,6 +299,8 @@ class CoroutineInferenceSupport(
private fun KotlinType.containsTypeTemplate() = contains { it is TypeTemplate || it is StubTypeForBuilderInference }
fun isApplicableCallForBuilderInference(descriptor: CallableDescriptor, languageVersionSettings: LanguageVersionSettings): Boolean {
if (languageVersionSettings.supportsFeature(LanguageFeature.StableBuilderInference)) return true
if (!languageVersionSettings.supportsFeature(LanguageFeature.ExperimentalBuilderInference)) {
return isGoodCallForOldCoroutines(descriptor)
}
@@ -95,6 +95,13 @@ class KotlinResolutionStatelessCallbacksImpl(
override fun isCoroutineCall(argument: KotlinCallArgument, parameter: ValueParameterDescriptor): Boolean =
isCoroutineCallWithAdditionalInference(parameter, argument.psiCallArgument.valueArgument, languageVersionSettings)
override fun isApplicableCallForBuilderInference(
descriptor: CallableDescriptor,
languageVersionSettings: LanguageVersionSettings,
): Boolean {
return org.jetbrains.kotlin.resolve.calls.inference.isApplicableCallForBuilderInference(descriptor, languageVersionSettings)
}
override fun isOldIntersectionIsEmpty(types: Collection<KotlinType>): Boolean {
return TypeIntersector.intersectTypes(types) == null
}
@@ -39,6 +39,7 @@ interface KotlinResolutionStatelessCallbacks {
fun getScopeTowerForCallableReferenceArgument(argument: CallableReferenceKotlinCallArgument): ImplicitScopeTower
fun getVariableCandidateIfInvoke(functionCall: KotlinCall): KotlinResolutionCandidate?
fun isCoroutineCall(argument: KotlinCallArgument, parameter: ValueParameterDescriptor): Boolean
fun isApplicableCallForBuilderInference(descriptor: CallableDescriptor, languageVersionSettings: LanguageVersionSettings): Boolean
fun isOldIntersectionIsEmpty(types: Collection<KotlinType>): Boolean
@@ -201,12 +201,12 @@ enum class LanguageFeature(
ProhibitSelfCallsInNestedObjects(KOTLIN_1_6, kind = BUG_FIX),
ApproximateIntegerLiteralTypesInReceiverPosition(KOTLIN_1_6),
ProperCheckAnnotationsTargetInTypeUsePositions(KOTLIN_1_6, kind = BUG_FIX),
DefinitelyNotNullTypeParameters(KOTLIN_1_6),
ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated(KOTLIN_1_6, kind = BUG_FIX),
AbstractClassMemberNotImplementedWithIntermediateAbstractClass(KOTLIN_1_6, kind = BUG_FIX),
SuspendFunctionAsSupertype(KOTLIN_1_6),
StableBuilderInference(KOTLIN_1_6),
ProperTypeInferenceConstraintsProcessing(KOTLIN_1_6, kind = BUG_FIX),
// Temporarily disabled, see KT-27084/KT-22379