mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CSSimplify] Diagnose an attempt to match non-existential type to an existential one
Resolves: rdar://159401910
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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'}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user