Skip to content

Commit 8b278ff

Browse files
committed
[Diagnostics] Adjust Self conformance check to find non-decl overload choices
Use `findSelectedOverloadFor` instead of `findResolvedMemberRef` to cover cases where member is found via base type unwrap, otherwise conformance constraint would be re-inserted but never re-attempted which results in a compiler crash. Resolves: rdar://79268378 (cherry picked from commit be6e2fa)
1 parent eaa6f5e commit 8b278ff

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)