Skip to content

Commit 34f8073

Browse files
committed
[Archetype builder] Allow non-concrete conformances with same-type-to-concrete requirements.
Fixes rdar://problem/29279577.
1 parent 6a7d257 commit 34f8073

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lib/AST/ArchetypeBuilder.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ bool ArchetypeBuilder::addSameTypeRequirementToConcrete(
12521252
}
12531253

12541254
// Make sure the concrete type fulfills the requirements on the archetype.
1255-
DenseMap<ProtocolDecl *, ProtocolConformance*> conformances;
1255+
DenseMap<ProtocolDecl *, ProtocolConformanceRef> conformances;
12561256
if (!Concrete->is<ArchetypeType>()) {
12571257
for (auto conforms : T->getConformsTo()) {
12581258
auto protocol = conforms.first;
@@ -1265,8 +1265,7 @@ bool ArchetypeBuilder::addSameTypeRequirementToConcrete(
12651265
return true;
12661266
}
12671267

1268-
assert(conformance->isConcrete() && "Abstract conformance?");
1269-
conformances[protocol] = conformance->getConcrete();
1268+
conformances.insert({protocol, *conformance});
12701269
}
12711270
}
12721271

@@ -1288,9 +1287,16 @@ bool ArchetypeBuilder::addSameTypeRequirementToConcrete(
12881287
} else {
12891288
assert(conformances.count(assocType->getProtocol()) > 0
12901289
&& "missing conformance?");
1291-
auto witness = conformances[assocType->getProtocol()]
1292-
->getTypeWitness(assocType, getLazyResolver());
1293-
auto witnessType = witness.getReplacement();
1290+
auto conformance = conformances.find(assocType->getProtocol())->second;
1291+
Type witnessType;
1292+
if (conformance.isConcrete()) {
1293+
witnessType = conformance.getConcrete()
1294+
->getTypeWitness(assocType, getLazyResolver())
1295+
.getReplacement();
1296+
} else {
1297+
witnessType = DependentMemberType::get(Concrete, assocType);
1298+
}
1299+
12941300
if (auto witnessPA = resolveArchetype(witnessType)) {
12951301
addSameTypeRequirementBetweenArchetypes(nested.second.front(),
12961302
witnessPA,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-parse-verify-swift
2+
// REQUIRES: objc_interop
3+
4+
@objc protocol Q {}
5+
6+
struct X1<T: AnyObject> { }
7+
8+
extension X1 where T == Q { }

0 commit comments

Comments
 (0)