Merge pull request #27614 from xedin/inout-type-mismatch

[ConstraintSystem] Detect and diagnose type mismatch failures of `ino…
This commit is contained in:
Pavel Yaskevich
2019-10-11 14:14:09 -07:00
committed by GitHub
7 changed files with 54 additions and 20 deletions

View File

@@ -2654,11 +2654,23 @@ bool ConstraintSystem::repairFailures(
auto result = matchTypes(lhs, rhs, ConstraintKind::Conversion,
TMF_ApplyingFix, locator);
if (!result.isFailure()) {
conversionsOrFixes.push_back(
AllowInOutConversion::create(*this, lhs, rhs, loc));
break;
ConstraintFix *fix = nullptr;
if (result.isFailure()) {
// If this is a "destination" argument to a mutating operator
// like `+=`, let's consider it contextual and only attempt
// to fix type mismatch on the "source" right-hand side of
// such operators.
if (isOperatorArgument(loc) &&
loc->findLast<LocatorPathElt::ApplyArgToParam>()->getArgIdx() == 0)
break;
fix = AllowArgumentMismatch::create(*this, lhs, rhs, loc);
} else {
fix = AllowInOutConversion::create(*this, lhs, rhs, loc);
}
conversionsOrFixes.push_back(fix);
break;
}
if (elt.getKind() != ConstraintLocator::ApplyArgToParam)