[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:
Pavel Yaskevich
2019-09-02 10:36:35 -07:00
parent 1a57fc403a
commit 93b39c9c23
6 changed files with 112 additions and 23 deletions

View File

@@ -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;