mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +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
This commit is contained in:
@@ -4311,6 +4311,15 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
|
|||||||
break;
|
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
|
// TODO(diagnostics): If there are any requirement failures associated
|
||||||
// with result types which are part of a function type conversion,
|
// with result types which are part of a function type conversion,
|
||||||
// let's record general conversion mismatch in order for it to capture
|
// let's record general conversion mismatch in order for it to capture
|
||||||
|
|||||||
@@ -577,3 +577,11 @@ do {
|
|||||||
|
|
||||||
isFooableError(overloaded()) // Ok
|
isFooableError(overloaded()) // Ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
func takesFooables(_: [any Fooable]) {}
|
||||||
|
|
||||||
|
func test(v: String) {
|
||||||
|
takesFooables([v]) // expected-error {{cannot convert value of type 'String' to expected element type 'any Fooable'}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user