mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Sema: Clean up leading dot fix logic in simplifyConformsToConstraint()
Tests still pass without this code, including the tests I just added in the previous commit.
This commit is contained in:
@@ -8859,7 +8859,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
|
||||
auto formUnsolved = [&](bool activate = false) {
|
||||
auto formUnsolved = [&]() {
|
||||
// If we're supposed to generate constraints, do so.
|
||||
if (flags.contains(TMF_GenerateConstraints)) {
|
||||
auto *conformance = Constraint::create(
|
||||
@@ -8867,9 +8867,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
|
||||
getConstraintLocator(locator));
|
||||
|
||||
addUnsolvedConstraint(conformance);
|
||||
if (activate)
|
||||
activateConstraint(conformance);
|
||||
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
|
||||
@@ -9243,46 +9240,41 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
|
||||
|
||||
if (isExpr<UnresolvedMemberExpr>(anchor) &&
|
||||
req->is<LocatorPathElt::TypeParameterRequirement>()) {
|
||||
auto *memberLoc = getConstraintLocator(anchor, path.front());
|
||||
|
||||
auto signature = path[path.size() - 2]
|
||||
.castTo<LocatorPathElt::OpenedGeneric>()
|
||||
.getSignature();
|
||||
auto requirement = signature.getRequirements()[req->getIndex()];
|
||||
|
||||
auto *memberLoc = getConstraintLocator(anchor, path.front());
|
||||
auto overload = findSelectedOverloadFor(memberLoc);
|
||||
auto attemptInvalidStaticMemberRefOnMetatypeFix = [&]() {
|
||||
// If the failed requirement isn't the first generic parameter,
|
||||
// it can't be a static member reference on a protocol metatype.
|
||||
if (!requirement.getFirstType()->isEqual(getASTContext().TheSelfType))
|
||||
return false;
|
||||
|
||||
// To figure out what is going on here we need to wait until
|
||||
// member overload is set in the constraint system.
|
||||
if (!overload) {
|
||||
// If it's not allowed to generate new constraints
|
||||
// there is no way to control re-activation, so this
|
||||
// check has to fail.
|
||||
if (!flags.contains(TMF_GenerateConstraints))
|
||||
return SolutionKind::Error;
|
||||
// If we don't know the overload yet, conservatively assume it's
|
||||
// a static member reference on a protocol metatype.
|
||||
auto overload = findSelectedOverloadFor(memberLoc);
|
||||
if (!overload)
|
||||
return true;
|
||||
|
||||
return formUnsolved(/*activate=*/true);
|
||||
}
|
||||
auto *decl = overload->choice.getDeclOrNull();
|
||||
if (!decl)
|
||||
return true;
|
||||
|
||||
auto *memberRef = overload->choice.getDeclOrNull();
|
||||
if (!memberRef)
|
||||
return SolutionKind::Error;
|
||||
// Otherwise, we can do a precise check.
|
||||
if (!decl->isStatic())
|
||||
return false;
|
||||
|
||||
// If this is a `Self` conformance requirement from a static member
|
||||
// reference on a protocol metatype, let's produce a tailored diagnostic.
|
||||
if (memberRef->isStatic()) {
|
||||
if (hasFixFor(memberLoc,
|
||||
FixKind::AllowInvalidStaticMemberRefOnProtocolMetatype))
|
||||
return SolutionKind::Solved;
|
||||
return decl->getDeclContext()->getSelfProtocolDecl() != nullptr;
|
||||
};
|
||||
|
||||
if (auto *protocolDecl =
|
||||
memberRef->getDeclContext()->getSelfProtocolDecl()) {
|
||||
auto selfTy = protocolDecl->getSelfInterfaceType();
|
||||
if (selfTy->isEqual(requirement.getFirstType())) {
|
||||
auto *fix = AllowInvalidStaticMemberRefOnProtocolMetatype::create(
|
||||
*this, memberLoc);
|
||||
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
|
||||
}
|
||||
}
|
||||
if (attemptInvalidStaticMemberRefOnMetatypeFix()) {
|
||||
auto *fix = AllowInvalidStaticMemberRefOnProtocolMetatype::create(
|
||||
*this, memberLoc);
|
||||
|
||||
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ test_combo(.genericFn(42)) // expected-error {{global function 'test_combo' requ
|
||||
|
||||
extension P { // expected-note 13 {{missing same-type requirement on 'Self'}} {{12-12= where Self == <#Type#>}}
|
||||
static func generic<T>(_: T) -> T { fatalError() }
|
||||
static func genericWithReqs<T: Collection, Q>(_: T) -> Q where T.Element == Q { // expected-note {{required by static method 'genericWithReqs' where 'T' = '()'}}
|
||||
static func genericWithReqs<T: Collection, Q>(_: T) -> Q where T.Element == Q { // expected-note 3 {{required by static method 'genericWithReqs' where 'T' = '()'}}
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
@@ -246,7 +246,9 @@ test(.genericWithReqs([S()])) // expected-error {{contextual member reference to
|
||||
test(.genericWithReqs([42]))
|
||||
// expected-error@-1 {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
|
||||
test(.genericWithReqs(()))
|
||||
// expected-error@-1 {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
|
||||
// expected-error@-1 {{type '()' cannot conform to 'Collection'}}
|
||||
// expected-note@-2 {{only concrete types such as structs, enums and classes can conform to protocols}}
|
||||
// expected-error@-3 {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
|
||||
|
||||
test_combo(.doesntExist) // expected-error {{reference to member 'doesntExist' cannot be resolved without a contextual type}}
|
||||
test_combo(.doesnt.exist()) // expected-error {{reference to member 'doesnt' cannot be resolved without a contextual type}}
|
||||
@@ -262,7 +264,9 @@ test_combo(.genericWithReqs([S()])) // expected-error {{contextual member refere
|
||||
test_combo(.genericWithReqs([42]))
|
||||
// expected-error@-1 {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
|
||||
test_combo(.genericWithReqs(()))
|
||||
// expected-error@-1 {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
|
||||
// expected-error@-1 {{type '()' cannot conform to 'Collection'}}
|
||||
// expected-note@-2 {{only concrete types such as structs, enums and classes can conform to protocols}}
|
||||
// expected-error@-3 {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
|
||||
|
||||
protocol TestWithAssoc {
|
||||
associatedtype U
|
||||
|
||||
Reference in New Issue
Block a user