diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index 0b24afeacad..5a4ecbc47c3 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -899,4 +899,23 @@ internal object CheckContextReceiversResolutionPart : ResolutionPart() { addDiagnostic(NoContextReceiver(candidateContextReceiverParameter)) return null } +} + +internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionPart() { + override fun ResolutionCandidate.process(workIndex: Int) = with(getSystem().asConstraintSystemCompleterContext()) { + val typeVariables = getSystem().getBuilder().currentStorage().notFixedTypeVariables.values + + for (variableWithConstraints in typeVariables) { + val upperTypes = variableWithConstraints.constraints.extractUpperTypes() + + if (upperTypes.isEmptyIntersection()) { + val isInferredEmptyIntersectionForbidden = + callComponents.languageVersionSettings.supportsFeature(LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection) + + val errorFactory = + if (isInferredEmptyIntersectionForbidden) ::InferredEmptyIntersectionError else ::InferredEmptyIntersectionWarning + addError(errorFactory(upperTypes, variableWithConstraints.typeVariable)) + } + } + } } \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallKind.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallKind.kt index 51565360b75..14d121fa35a 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallKind.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallKind.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.resolve.calls.components.CheckCallableReference import org.jetbrains.kotlin.resolve.calls.components.CheckContextReceiversResolutionPart import org.jetbrains.kotlin.resolve.calls.components.CheckExplicitReceiverKindConsistency import org.jetbrains.kotlin.resolve.calls.components.CheckExternalArgument +import org.jetbrains.kotlin.resolve.calls.components.CheckIncompatibleTypeVariableUpperBounds import org.jetbrains.kotlin.resolve.calls.components.CheckInfixResolutionPart import org.jetbrains.kotlin.resolve.calls.components.CheckOperatorResolutionPart import org.jetbrains.kotlin.resolve.calls.components.CheckReceivers @@ -38,7 +39,8 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) { CheckExplicitReceiverKindConsistency, CheckReceivers, PostponedVariablesInitializerResolutionPart, - CheckContextReceiversResolutionPart + CheckContextReceiversResolutionPart, + CheckIncompatibleTypeVariableUpperBounds ), FUNCTION( CheckVisibility, @@ -58,7 +60,8 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) { CompatibilityOfTypeVariableAsIntersectionTypePart, CompatibilityOfPartiallyApplicableSamConversion, PostponedVariablesInitializerResolutionPart, - CheckContextReceiversResolutionPart + CheckContextReceiversResolutionPart, + CheckIncompatibleTypeVariableUpperBounds ), INVOKE(*FUNCTION.resolutionSequence.toTypedArray()), CALLABLE_REFERENCE( @@ -69,7 +72,8 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) { CollectionTypeVariableUsagesInfo, CheckReceivers, CheckCallableReference, - CompatibilityOfTypeVariableAsIntersectionTypePart + CompatibilityOfTypeVariableAsIntersectionTypePart, + CheckIncompatibleTypeVariableUpperBounds ), UNSUPPORTED();