[CS] Better diagnose conformance failures for EnumElementPatterns

Previously we could end up with a
ContextualMismatch fix and a MissingConformance fix
for different elements of the `matchTypes` disjunction,
leading to an ambiguity. Instead, avoid recording
the ContextualMismatch if we're matching an
existential, and tweak the MissingConformance
failure to have a custom diagnostic for
EnumElementPattern matching.
This commit is contained in:
Hamish Knight
2024-07-15 12:47:50 +01:00
parent cd1b6eddc2
commit d6d8d08608
5 changed files with 30 additions and 1 deletions

View File

@@ -6667,6 +6667,11 @@ bool ConstraintSystem::repairFailures(
if (lhs->isPlaceholder() || rhs->isPlaceholder())
return true;
// If we're converting to an existential, we'll diagnose failures in
// the conformance constraint.
if (hasConversionOrRestriction(ConversionRestrictionKind::Existential))
return false;
conversionsOrFixes.push_back(ContextualMismatch::create(
*this, lhs, rhs, getConstraintLocator(locator)));
break;