[FE 1.0] Check if type variable is bounded in upper by incompatible types (resolution stage)

^KT-51221 Fixed
This commit is contained in:
Victor Petukhov
2022-02-11 11:41:24 +03:00
committed by teamcity
parent 9e9e0211eb
commit e7bd464a3c
2 changed files with 26 additions and 3 deletions
@@ -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))
}
}
}
}
@@ -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();