[TypeChecker] Produce a tailored diagnostic for for-in sequence failures

`for-in` "sequence" expression is required to conform to `Sequence`.
This commit is contained in:
Pavel Yaskevich
2019-10-22 10:27:38 -07:00
parent 049d56a58f
commit 74a7f3d8d0
13 changed files with 76 additions and 21 deletions

View File

@@ -3357,6 +3357,25 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
formUnsolvedResult);
}
}
// If the left-hand side of a 'sequence element' constraint
// is a dependent member type without any type variables it
// means that conformance check has been "fixed".
// Let's record other side of the conversion as a "hole"
// to give the solver a chance to continue and avoid
// producing diagnostics for both missing conformance and
// invalid element type.
if (shouldAttemptFixes()) {
if (auto last = locator.last()) {
if (last->is<LocatorPathElt::SequenceElementType>() &&
desugar1->is<DependentMemberType>() &&
!desugar1->hasTypeVariable()) {
recordHole(typeVar2);
return getTypeMatchSuccess();
}
}
}
return formUnsolvedResult();
}