mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CSSimplify] Remove all InstanceType at the end of a locator to diagnose mismatched existential conversion
This commit is contained in:
@@ -8755,8 +8755,17 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
|
||||
if (shouldAttemptFixes() && result.isFailure()) {
|
||||
auto *loc = getConstraintLocator(locator);
|
||||
|
||||
if (loc->isLastElement<LocatorPathElt::InstanceType>())
|
||||
loc = getConstraintLocator(loc->getAnchor(), loc->getPath().drop_back());
|
||||
ArrayRef<LocatorPathElt> path = loc->getPath();
|
||||
while (!path.empty()) {
|
||||
if (!path.back().is<LocatorPathElt::InstanceType>())
|
||||
break;
|
||||
|
||||
path = path.drop_back();
|
||||
}
|
||||
|
||||
if (path.size() != loc->getPath().size()) {
|
||||
loc = getConstraintLocator(loc->getAnchor(), path);
|
||||
}
|
||||
|
||||
ConstraintFix *fix = nullptr;
|
||||
if (loc->isLastElement<LocatorPathElt::ApplyArgToParam>()) {
|
||||
|
||||
@@ -125,7 +125,8 @@ func parameterizedExistentials() {
|
||||
func testNestedMetatype() {
|
||||
struct S: P {}
|
||||
|
||||
func bar<T>(_ x: T) -> T.Type { type(of: x) }
|
||||
func bar<T>(_ x: T) -> T.Type { }
|
||||
func metaBar<T>(_ x: T) -> T.Type.Type { }
|
||||
func foo1(_ x: P.Type) {}
|
||||
func foo2(_ x: P.Type.Type) { }
|
||||
|
||||
@@ -134,4 +135,5 @@ func testNestedMetatype() {
|
||||
// Make sure we don't crash.
|
||||
foo2(bar(S.self))
|
||||
foo2(bar(0)) // expected-error {{cannot convert value of type 'Int' to expected argument type 'any P.Type'}}
|
||||
foo2(metaBar(0)) // expected-error {{argument type 'Int' does not conform to expected type 'P'}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user