Skip to content

Commit c9e9c90

Browse files
authored
Merge pull request #12993 from DougGregor/interface-types-conformances-vapor
2 parents b56786f + a322628 commit c9e9c90

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5447,15 +5447,42 @@ void ConformanceChecker::ensureRequirementsAreSatisfied() {
54475447
ProtocolConformanceRef conformance) override {
54485448
// The conformance will use contextual types, but we want the
54495449
// interface type equivalent.
5450+
5451+
// If we have an inherited conformance for an archetype, dig out the
5452+
// superclass conformance to translate.
5453+
Type inheritedInterfaceType;
54505454
if (conformance.isConcrete() &&
54515455
conformance.getConcrete()->getType()->hasArchetype()) {
5456+
auto concreteConformance = conformance.getConcrete();
5457+
if (concreteConformance->getKind()
5458+
== ProtocolConformanceKind::Inherited &&
5459+
conformance.getConcrete()->getType()->is<ArchetypeType>()) {
5460+
inheritedInterfaceType =
5461+
concreteConformance->getType()->mapTypeOutOfContext();
5462+
concreteConformance =
5463+
cast<InheritedProtocolConformance>(concreteConformance)
5464+
->getInheritedConformance();
5465+
}
5466+
5467+
// Map the conformance.
5468+
// FIXME: It would be so much easier and efficient if we had
5469+
// ProtocolConformance::mapTypesOutOfContext().
54525470
auto interfaceType =
5453-
conformance.getConcrete()->getType()->mapTypeOutOfContext();
5471+
concreteConformance->getType()->mapTypeOutOfContext();
5472+
54545473
conformance = *tc.conformsToProtocol(
5455-
interfaceType,
5456-
conformance.getRequirement(),
5457-
dc,
5458-
ConformanceCheckFlags::SuppressDependencyTracking);
5474+
interfaceType,
5475+
conformance.getRequirement(),
5476+
dc,
5477+
ConformanceCheckFlags::SuppressDependencyTracking);
5478+
5479+
// Reinstate inherited conformance.
5480+
if (inheritedInterfaceType) {
5481+
conformance =
5482+
ProtocolConformanceRef(
5483+
tc.Context.getInheritedConformance(inheritedInterfaceType,
5484+
conformance.getConcrete()));
5485+
}
54595486
}
54605487

54615488
writer(conformance);

0 commit comments

Comments
 (0)