diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt index 555c90c96f9..4b75a10b7a8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt @@ -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 { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceUtil.kt index 60bce8d0a9b..baa769ad078 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/CoroutineInferenceUtil.kt @@ -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) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt index 5a83e5bda16..789203ef1e7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt @@ -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): Boolean { return TypeIntersector.intersectTypes(types) == null } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt index 6c6a607c37d..edd3b2de0b9 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt @@ -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): Boolean diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index ada29dc8560..26948a0d999 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -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