[ConstraintSystem] Port function parameter type mismatch diagnostics.

This commit is contained in:
Holly Borla
2019-12-09 16:47:10 -08:00
parent edb4e70d66
commit 51c7c8c8f1
8 changed files with 144 additions and 143 deletions

View File

@@ -3543,19 +3543,21 @@ bool ConstraintSystem::repairFailures(
// Drop the `tuple element` locator element so that all tuple element
// mismatches within the same tuple type can be coalesced later.
auto index = elt.getAs<LocatorPathElt::TupleElement>()->getIndex();
path.pop_back();
auto *tupleLocator = getConstraintLocator(locator.getAnchor(), path);
// TODO: Add a tailored fix for function parameter type mismatches.
// Let this fail if it's a contextual mismatch with sequence element types,
// as there's a special fix for that.
if (tupleLocator->isLastElement<LocatorPathElt::FunctionArgument>() ||
tupleLocator->isLastElement<LocatorPathElt::SequenceElementType>())
if (tupleLocator->isLastElement<LocatorPathElt::SequenceElementType>())
break;
auto index = elt.getAs<LocatorPathElt::TupleElement>()->getIndex();
auto *fix =
AllowTupleTypeMismatch::create(*this, lhs, rhs, tupleLocator, index);
ConstraintFix *fix;
if (tupleLocator->isLastElement<LocatorPathElt::FunctionArgument>()) {
fix = AllowFunctionTypeMismatch::create(*this, lhs, rhs, tupleLocator, index);
} else {
fix = AllowTupleTypeMismatch::create(*this, lhs, rhs, tupleLocator, index);
}
conversionsOrFixes.push_back(fix);
break;
}
@@ -8533,6 +8535,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
return matchTupleTypes(matchingType, smaller, matchKind, subflags, locator);
}
case FixKind::AllowFunctionTypeMismatch: {
if (recordFix(fix, /*impact=*/5))
return SolutionKind::Error;
return SolutionKind::Solved;
}
case FixKind::TreatEphemeralAsNonEphemeral: {
auto *theFix = static_cast<TreatEphemeralAsNonEphemeral *>(fix);
// If we have a non-ephemeral locator for an ephemeral conversion, make a