Skip to content

Commit 09d6d23

Browse files
authored
Merge pull request swiftlang#38069 from xedin/rdar-79268378-5.5
[5.5][Diagnostics] Adjust `Self` conformance check to find non-decl overload choices
2 parents 879ce16 + 8b278ff commit 09d6d23

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
@@ -6312,12 +6312,23 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
63126312
auto requirement = signature->getRequirements()[req->getIndex()];
63136313

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

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

63226333
// If this is a `Self` conformance requirement from a static member
63236334
// 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)