Skip to content

Commit 0a7b977

Browse files
committed
[GSB] "Self: P" in requirement signatures aren't self-derived.
When determining whether a conformance requirement source is self-derived, ignore the top-level "Self: P" requirement in a requirement signature. Fixes SR-5485 / rdar://problem/33360699.
1 parent 6177f83 commit 0a7b977

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ bool RequirementSource::isSelfDerivedConformance(
419419
switch (source->kind) {
420420
case ProtocolRequirement:
421421
case InferredProtocolRequirement: {
422+
// For a requirement signature, we ignore the 'Self: P' requirement
423+
// for the purposes of the self-derived check.
424+
if (source->parent->kind == RequirementSource::RequirementSignatureSelf)
425+
return false;
426+
422427
// Note that we've seen a protocol requirement.
423428
sawProtocolRequirement = true;
424429

test/decl/protocol/recursive_requirement_ok.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@ func testP<T: P>(_ t: T) {
1212
testP(t.assoc.assoc.assoc)
1313
testP(t.assoc.assoc.assoc.assoc.assoc.assoc.assoc)
1414
}
15+
16+
// SR-5485
17+
protocol P1 {
18+
associatedtype X : P2
19+
}
20+
protocol P2 {
21+
associatedtype Y : P1 where Y.X == Self // expected-note{{conformance constraint 'Self.Z': 'P1' implied here}}
22+
associatedtype Z : P1 // expected-warning{{redundant conformance constraint 'Self.Z': 'P1'}}
23+
}

0 commit comments

Comments
 (0)