[FE 1.0] Don't fail candidates which were marked with compatibility resolve previously

^KT-52431 Fixed
^KT-52393 Fixed
This commit is contained in:
Victor Petukhov
2022-05-20 14:09:22 +02:00
committed by teamcity
parent 73d676d9de
commit 02a430875f
17 changed files with 198 additions and 23 deletions
@@ -152,7 +152,8 @@ class InferredEmptyIntersectionError(
class OnlyInputTypesDiagnostic(val typeVariable: TypeVariableMarker) : ConstraintSystemError(INAPPLICABLE)
object LowerPriorityToPreserveCompatibility : ConstraintSystemError(RESOLVED_NEED_PRESERVE_COMPATIBILITY)
class LowerPriorityToPreserveCompatibility(val needToReportWarning: Boolean) :
ConstraintSystemError(RESOLVED_NEED_PRESERVE_COMPATIBILITY)
fun Constraint.isExpectedTypePosition() =
position.from is ExpectedTypeConstraintPosition<*> || position.from is DelegatedPropertyConstraintPosition<*>
@@ -450,9 +450,13 @@ class NewConstraintSystemImpl(
languageVersionSettings.supportsFeature(LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection)
val upperTypes = intersectionTypeConstructor.supertypes()
// Diagnostic with these incompatible types has already been reported at the resolution stage
if (upperTypes.size <= 1 || storage.errors.any { it is InferredEmptyIntersection && it.incompatibleTypes == upperTypes })
return
if (upperTypes.computeEmptyIntersectionTypeKind().isDefinitelyEmpty()) {
// Remove existing errors from resolution stage because a completion error is more precise
storage.errors.removeIf { it is InferredEmptyIntersectionError || it is InferredEmptyIntersectionWarning }
storage.errors.removeIf { it is InferredEmptyIntersection }
val errorFactory =
if (isInferredEmptyIntersectionForbidden) ::InferredEmptyIntersectionError else ::InferredEmptyIntersectionWarning
addError(errorFactory(upperTypes, variable))