Skip to content

Commit 6a7d257

Browse files
committed
[Archetype builder] Mark same-type constraints on nested types as redundant.
When a same-type constraint equates a potential archetype with a same-type constraint, it implies equality of the nested types with the appropriate witnesses. However, these were getting marked as "explicit" when they should be "redundant". Fixes rdar://problem/29295062.
1 parent 125ad63 commit 6a7d257

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/AST/ArchetypeBuilder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,7 @@ bool ArchetypeBuilder::addSameTypeRequirementToConcrete(
12751275
T->SameTypeSource = Source;
12761276

12771277
// Recursively resolve the associated types to their concrete types.
1278+
RequirementSource nestedSource(RequirementSource::Redundant, Source.getLoc());
12781279
for (auto nested : T->getNestedTypes()) {
12791280
AssociatedTypeDecl *assocType
12801281
= nested.second.front()->getResolvedAssociatedType();
@@ -1283,7 +1284,7 @@ bool ArchetypeBuilder::addSameTypeRequirementToConcrete(
12831284
concreteArchetype->getNestedType(nested.first);
12841285
addSameTypeRequirementToConcrete(nested.second.front(),
12851286
witnessType.getValue(),
1286-
Source);
1287+
nestedSource);
12871288
} else {
12881289
assert(conformances.count(assocType->getProtocol()) > 0
12891290
&& "missing conformance?");
@@ -1293,11 +1294,11 @@ bool ArchetypeBuilder::addSameTypeRequirementToConcrete(
12931294
if (auto witnessPA = resolveArchetype(witnessType)) {
12941295
addSameTypeRequirementBetweenArchetypes(nested.second.front(),
12951296
witnessPA,
1296-
Source);
1297+
nestedSource);
12971298
} else {
12981299
addSameTypeRequirementToConcrete(nested.second.front(),
12991300
witnessType,
1300-
Source);
1301+
nestedSource);
13011302
}
13021303
}
13031304
}

test/Generics/requirement_inference.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ func inferSameType2<T : P3, U : P4>(_: T) where U.P4Assoc : P2, T.P3Assoc == U.P
136136
// CHECK-NEXT: Generic signature
137137
func inferSameType3<T : PCommonAssoc1>(_: T) where T.CommonAssoc : P1, T : PCommonAssoc2 {}
138138

139+
struct X6 : PAssoc {
140+
typealias Assoc = X6
141+
}
142+
143+
// CHECK-LABEL: .inferSameType4@
144+
// CHECK-NEXT: Requirements:
145+
// CHECK-NEXT: T : PAssoc [explicit @
146+
// CHECK-NEXT: T[.PAssoc].Assoc == X6 [explicit
147+
// CHECK-NEXT: T[.PAssoc].Assoc[.PAssoc].Assoc == X6.Assoc [redundant
148+
// CHECK-NEXT: T[.PAssoc].Assoc[.PAssoc].Assoc[.PAssoc].Assoc == X6.Assoc [redundant
149+
// CHECK-NEXT: Generic signature: <T where T : PAssoc, T.Assoc == X6>
150+
// CHECK-NEXT: Canonical generic signature: <τ_0_0 where τ_0_0 : PAssoc, τ_0_0.Assoc == X6>
151+
func inferSameType4<T : PAssoc>(_: T) where T.Assoc : PAssoc, T.Assoc.Assoc : PAssoc, T.Assoc == X6 {}
152+
139153
protocol P5 {
140154
associatedtype Element
141155
}

0 commit comments

Comments
 (0)