Skip to content

[Diagnostics] Adjust Self conformance check to find non-decl overload choices #38045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 13 additions & 2 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6310,12 +6310,23 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
auto requirement = signature->getRequirements()[req->getIndex()];

auto *memberLoc = getConstraintLocator(anchor, path.front());
auto *memberRef = findResolvedMemberRef(memberLoc);
auto overload = findSelectedOverloadFor(memberLoc);

// To figure out what is going on here we need to wait until
// member overload is set in the constraint system.
if (!memberRef)
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;

return formUnsolved(/*activate=*/true);
}

auto *memberRef = overload->choice.getDeclOrNull();
if (!memberRef)
return SolutionKind::Error;

// If this is a `Self` conformance requirement from a static member
// reference on a protocol metatype, let's produce a tailored diagnostic.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: not %target-swift-frontend %s -typecheck

struct Result {
}

func wrapper(_: Result?) {
}

extension Optional where Wrapped == Result {
static func test(_: String) -> Result { Result() }
}

extension Result {
static func test<R: RangeExpression>(_: R) -> Result where R.Bound == Int {
Result()
}
}

protocol P {}

struct Value : P {
init() {}
init<R>(_: R) {}
}

func example<T1: P, T2: P>(_: T1, _: T2) {
}

example(Value(), Value(wrapper(.test(0))))