[FE 1.0] Check if type variable is bounded in upper by incompatible types (resolution stage)
^KT-51221 Fixed
This commit is contained in:
committed by
teamcity
parent
9e9e0211eb
commit
e7bd464a3c
+19
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user