Use proper applicability for constraint warnings

^KT-47316 Fixed
This commit is contained in:
Victor Petukhov
2021-06-18 11:23:43 +03:00
committed by TeamCityServer
parent 1224d28deb
commit c3a5a7754d
22 changed files with 443 additions and 35 deletions
@@ -91,12 +91,24 @@ object SimpleConstraintSystemConstraintPosition : ConstraintPosition()
sealed class ConstraintSystemError(val applicability: CandidateApplicability)
sealed interface NewConstraintMismatch {
val lowerType: KotlinTypeMarker
val upperType: KotlinTypeMarker
val position: IncorporationConstraintPosition
}
class NewConstraintError(
val lowerType: KotlinTypeMarker,
val upperType: KotlinTypeMarker,
val position: IncorporationConstraintPosition,
val isWarning: Boolean = false
) : ConstraintSystemError(if (position.from is ReceiverConstraintPosition<*>) INAPPLICABLE_WRONG_RECEIVER else INAPPLICABLE)
override val lowerType: KotlinTypeMarker,
override val upperType: KotlinTypeMarker,
override val position: IncorporationConstraintPosition,
) : ConstraintSystemError(if (position.from is ReceiverConstraintPosition<*>) INAPPLICABLE_WRONG_RECEIVER else INAPPLICABLE),
NewConstraintMismatch
class NewConstraintWarning(
override val lowerType: KotlinTypeMarker,
override val upperType: KotlinTypeMarker,
override val position: IncorporationConstraintPosition,
) : ConstraintSystemError(RESOLVED), NewConstraintMismatch
class CapturedTypeFromSubtyping(
val typeVariable: TypeVariableMarker,
@@ -122,4 +134,4 @@ object LowerPriorityToPreserveCompatibility : ConstraintSystemError(RESOLVED_NEE
fun Constraint.isExpectedTypePosition() =
position.from is ExpectedTypeConstraintPosition<*> || position.from is DelegatedPropertyConstraintPosition<*>
fun NewConstraintError.transformToWarning() = NewConstraintError(lowerType, upperType, position, isWarning = true)
fun NewConstraintError.transformToWarning() = NewConstraintWarning(lowerType, upperType, position)
@@ -386,7 +386,7 @@ class NewConstraintSystemImpl(
}
val constraintErrors = constraintSystem.errors.filterIsInstance<NewConstraintError>()
// Don't report warning if an error on the same call has already been reported
if (constraintErrors.isEmpty() || constraintErrors.all { it.isWarning }) {
if (constraintErrors.isEmpty()) {
errorsByMissedConstraints.forEach {
constraintSystem.addError(it.transformToWarning())
}