Skip to content

Commit 9733fb7

Browse files
authored
Merge pull request #38045 from xedin/rdar-79268378
[Diagnostics] Adjust `Self` conformance check to find non-decl overload choices
2 parents 00baabf + be6e2fa commit 9733fb7

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6310,12 +6310,23 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
63106310
auto requirement = signature->getRequirements()[req->getIndex()];
63116311

63126312
auto *memberLoc = getConstraintLocator(anchor, path.front());
6313-
auto *memberRef = findResolvedMemberRef(memberLoc);
6313+
auto overload = findSelectedOverloadFor(memberLoc);
63146314

63156315
// To figure out what is going on here we need to wait until
63166316
// member overload is set in the constraint system.
6317-
if (!memberRef)
6317+
if (!overload) {
6318+
// If it's not allowed to generate new constraints
6319+
// there is no way to control re-activation, so this
6320+
// check has to fail.
6321+
if (!flags.contains(TMF_GenerateConstraints))
6322+
return SolutionKind::Error;
6323+
63186324
return formUnsolved(/*activate=*/true);
6325+
}
6326+
6327+
auto *memberRef = overload->choice.getDeclOrNull();
6328+
if (!memberRef)
6329+
return SolutionKind::Error;
63196330

63206331
// If this is a `Self` conformance requirement from a static member
63216332
// reference on a protocol metatype, let's produce a tailored diagnostic.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: not %target-swift-frontend %s -typecheck
2+
3+
struct Result {
4+
}
5+
6+
func wrapper(_: Result?) {
7+
}
8+
9+
extension Optional where Wrapped == Result {
10+
static func test(_: String) -> Result { Result() }
11+
}
12+
13+
extension Result {
14+
static func test<R: RangeExpression>(_: R) -> Result where R.Bound == Int {
15+
Result()
16+
}
17+
}
18+
19+
protocol P {}
20+
21+
struct Value : P {
22+
init() {}
23+
init<R>(_: R) {}
24+
}
25+
26+
func example<T1: P, T2: P>(_: T1, _: T2) {
27+
}
28+
29+
example(Value(), Value(wrapper(.test(0))))

0 commit comments

Comments
 (0)