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

This commit is contained in:
Victor Petukhov
2022-02-11 11:44:03 +03:00
committed by teamcity
parent 095a5d1fdf
commit 9474406375
3 changed files with 29 additions and 2 deletions
@@ -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)
@@ -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<ConeKotlinType>,
variableWithConstraints.typeVariable as ConeTypeVariable
)
)
}
}
}
}
internal object PostponedVariablesInitializerResolutionStage : ResolutionStage() {
override suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) {
@@ -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),