Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8750,7 +8750,27 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
return SolutionKind::Solved;
}

return matchExistentialTypes(type, protocol, kind, flags, locator);
auto result = matchExistentialTypes(type, protocol, kind, flags, locator);

if (shouldAttemptFixes() && result.isFailure()) {
auto *loc = getConstraintLocator(locator);

if (loc->isLastElement<LocatorPathElt::InstanceType>())
loc = getConstraintLocator(loc->getAnchor(), loc->getPath().drop_back());

ConstraintFix *fix = nullptr;
if (loc->isLastElement<LocatorPathElt::ApplyArgToParam>()) {
fix = AllowArgumentMismatch::create(*this, type, protocol, loc);
} else if (loc->isLastElement<LocatorPathElt::ContextualType>()) {
fix = ContextualMismatch::create(*this, type, protocol, loc);
}

if (fix) {
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
}
}

return result;
}

void ConstraintSystem::recordSynthesizedConformance(
Expand Down
7 changes: 3 additions & 4 deletions test/Constraints/existential_metatypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ func parameterizedExistentials() {
pt = ppt // expected-error {{cannot assign value of type 'any PP4<Int>.Type' to type 'any P4<Int>.Type'}}
}

// https://github.com/swiftlang/swift/issues/83991

func testNestedMetatype() {
struct S: P {}

Expand All @@ -131,8 +133,5 @@ func testNestedMetatype() {

// Make sure we don't crash.
foo2(bar(S.self))

// FIXME: Bad diagnostic
// https://github.com/swiftlang/swift/issues/83991
foo2(bar(0)) // expected-error {{failed to produce diagnostic for expression}}
foo2(bar(0)) // expected-error {{cannot convert value of type 'Int' to expected argument type 'any P.Type'}}
}