diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt index fc5ab94a080..050fa063277 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt @@ -20,7 +20,8 @@ sealed class CallKind(vararg resolutionSequence: ResolutionStage) { CheckDslScopeViolation, CheckLowPriorityInOverloadResolution, PostponedVariablesInitializerResolutionStage, - ConstraintSystemForks + ConstraintSystemForks, + CheckIncompatibleTypeVariableUpperBounds, ) object SyntheticSelect : CallKind( @@ -31,6 +32,7 @@ sealed class CallKind(vararg resolutionSequence: ResolutionStage) { CheckArguments, EagerResolveOfCallableReferences, ConstraintSystemForks, + CheckIncompatibleTypeVariableUpperBounds, ) object Function : CallKind( @@ -52,6 +54,7 @@ sealed class CallKind(vararg resolutionSequence: ResolutionStage) { CheckLowPriorityInOverloadResolution, PostponedVariablesInitializerResolutionStage, ConstraintSystemForks, + CheckIncompatibleTypeVariableUpperBounds, ) object DelegatingConstructorCall : CallKind( @@ -68,6 +71,7 @@ sealed class CallKind(vararg resolutionSequence: ResolutionStage) { CheckArguments, EagerResolveOfCallableReferences, ConstraintSystemForks, + CheckIncompatibleTypeVariableUpperBounds, ) object CallableReference : CallKind( @@ -82,6 +86,7 @@ sealed class CallKind(vararg resolutionSequence: ResolutionStage) { CheckDslScopeViolation, CheckCallableReferenceExpectedType, CheckLowPriorityInOverloadResolution, + CheckIncompatibleTypeVariableUpperBounds, ) object SyntheticIdForCallableReferencesResolution : CallKind( @@ -92,6 +97,7 @@ sealed class CallKind(vararg resolutionSequence: ResolutionStage) { CheckArguments, EagerResolveOfCallableReferences, ConstraintSystemForks, + CheckIncompatibleTypeVariableUpperBounds, ) internal class CustomForIde(vararg resolutionSequence: ResolutionStage) : CallKind(*resolutionSequence) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt index a7ca887aa9f..7c8b3fdc8e0 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt @@ -576,6 +576,27 @@ internal object CheckLowPriorityInOverloadResolution : CheckerStage() { } } +internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionStage() { + override suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) = + with(candidate.system.asConstraintSystemCompleterContext()) { + val typeVariables = candidate.system.notFixedTypeVariables.values + + for (variableWithConstraints in typeVariables) { + val upperTypes = variableWithConstraints.constraints.extractUpperTypes() + + if (upperTypes.isEmptyIntersection()) { + sink.yieldDiagnostic( + @Suppress("UNCHECKED_CAST") + InferredEmptyIntersectionDiagnostic( + upperTypes as Collection, + variableWithConstraints.typeVariable as ConeTypeVariable + ) + ) + } + } + } +} + internal object PostponedVariablesInitializerResolutionStage : ResolutionStage() { override suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) { diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 41810fe4810..4612ac7c422 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -261,7 +261,6 @@ enum class LanguageFeature( ForbidUsingExtensionPropertyTypeParameterInDelegate(KOTLIN_1_8, kind = BUG_FIX), ModifierNonBuiltinSuspendFunError(KOTLIN_1_8), SynchronizedSuspendError(KOTLIN_1_8), - ForbidInferringTypeVariablesIntoEmptyIntersection(KOTLIN_1_8, kind = BUG_FIX), // KT-51221 // 1.9 @@ -275,6 +274,7 @@ enum class LanguageFeature( StopPropagatingDeprecationThroughOverrides(KOTLIN_1_9, kind = BUG_FIX), // KT-47902 ReportTypeVarianceConflictOnQualifierArguments(KOTLIN_1_9, kind = BUG_FIX), // KT-50947 ReportErrorsOnRecursiveTypeInsidePlusAssignment(KOTLIN_1_9, kind = BUG_FIX), // KT-48546 + ForbidInferringTypeVariablesIntoEmptyIntersection(KOTLIN_1_9, kind = BUG_FIX), // KT-51221 // Disabled for indefinite time. See KT-48535 and related discussion ApproximateIntegerLiteralTypesInReceiverPosition(sinceVersion = null),