mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Diagnostics] Port pattern-matching mismatch diagnostic
Port diagnostics associated with implicit use of `~=` operator which is used in `case` statements.
This commit is contained in:
@@ -2400,7 +2400,10 @@ bool ConstraintSystem::repairFailures(
|
||||
if (repairByInsertingExplicitCall(lhs, rhs))
|
||||
break;
|
||||
|
||||
if (repairViaBridgingCast(*this, lhs, rhs, conversionsOrFixes, locator))
|
||||
bool isPatternMatching = isArgumentOfPatternMatchingOperator(loc);
|
||||
// Let's not suggest force downcasts in pattern-matching context.
|
||||
if (!isPatternMatching &&
|
||||
repairViaBridgingCast(*this, lhs, rhs, conversionsOrFixes, locator))
|
||||
break;
|
||||
|
||||
// Argument is a r-value but parameter expects an l-value e.g.
|
||||
@@ -2580,6 +2583,13 @@ bool ConstraintSystem::repairFailures(
|
||||
if (hasConversionOrRestriction(ConversionRestrictionKind::DeepEquality))
|
||||
break;
|
||||
|
||||
// If this is a ~= operator implicitly generated by pattern matching
|
||||
// let's not try to fix right-hand side of the operator because it's
|
||||
// a correct contextual type.
|
||||
if (isPatternMatching &&
|
||||
elt.castTo<LocatorPathElt::ApplyArgToParam>().getParamIdx() == 1)
|
||||
break;
|
||||
|
||||
conversionsOrFixes.push_back(AllowArgumentMismatch::create(
|
||||
*this, lhs, rhs, getConstraintLocator(locator)));
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user