mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Diagnostics] Diagnose existential mismatch in a literal collection element position
If key or value of a literal collection expression doesn't conform
to protocol(s) expected by the contextual existential type, let's
diagnose that via a tailed collection mismatch fix instead of a
generic conformance one.
Resolves: rdar://103045274
(cherry picked from commit d83ec7b3a5)
This commit is contained in:
@@ -4311,6 +4311,15 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
|
||||
break;
|
||||
}
|
||||
|
||||
if ((isExpr<ArrayExpr>(anchor) || isExpr<DictionaryExpr>(anchor)) &&
|
||||
last.is<LocatorPathElt::TupleElement>()) {
|
||||
auto *fix = CollectionElementContextualMismatch::create(
|
||||
*this, type1, type2, getConstraintLocator(anchor, path));
|
||||
if (recordFix(fix, /*impact=*/2))
|
||||
return getTypeMatchFailure(locator);
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO(diagnostics): If there are any requirement failures associated
|
||||
// with result types which are part of a function type conversion,
|
||||
// let's record general conversion mismatch in order for it to capture
|
||||
|
||||
Reference in New Issue
Block a user