Skip to content

Commit d21d6f1

Browse files
committed
[Generic environment] Only substitute top-level archetypes.
The core substitution routine for the archetypes-to-interface types substitution was attempting to provide mappings for nested archetypes, when in fact these archetypes would (1) always be resolvable via their parent, and (2) could in fact cause infinite recursion, as with the new test case. Fixes SR-4617 / rdar://problem/31673819.
1 parent f6f5474 commit d21d6f1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/AST/GenericEnvironment.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ Type GenericEnvironment::QueryArchetypeToInterfaceSubstitutions::operator()(
227227
auto archetype = type->getAs<ArchetypeType>();
228228
if (!archetype) return Type();
229229

230+
// Only top-level archetypes need to be substituted directly; nested
231+
// archetypes will be handled via their root archetypes.
232+
if (archetype->getParent()) return Type();
233+
230234
// If not all generic parameters have had their context types recorded,
231235
// perform a linear search.
232236
auto genericParams = self->Signature->getGenericParams();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-frontend -primary-file %s -emit-ir
2+
3+
extension Dictionary {
4+
init<S: Sequence>(grouping elements: S, by keyForValue: (S.Iterator.Element) -> Key)
5+
where Array<S.Iterator.Element> == Value
6+
{
7+
self = [:]
8+
for value in elements {
9+
var values = self[keyForValue(value)] ?? []
10+
values.append(value)
11+
self[keyForValue(value)] = values
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)