[CSSimplify] Remove all InstanceType at the end of a locator to diagnose mismatched existential conversion

This commit is contained in:
Pavel Yaskevich
2025-10-06 14:01:28 -07:00
parent 36fc1e6c43
commit 15c56627b8
2 changed files with 14 additions and 3 deletions

View File

@@ -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>()) {

View File

@@ -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'}}
}