Skip to content

[Interface types in normal conformances] Cope with inherited conformances #12993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5447,15 +5447,42 @@ void ConformanceChecker::ensureRequirementsAreSatisfied() {
ProtocolConformanceRef conformance) override {
// The conformance will use contextual types, but we want the
// interface type equivalent.

// If we have an inherited conformance for an archetype, dig out the
// superclass conformance to translate.
Type inheritedInterfaceType;
if (conformance.isConcrete() &&
conformance.getConcrete()->getType()->hasArchetype()) {
auto concreteConformance = conformance.getConcrete();
if (concreteConformance->getKind()
== ProtocolConformanceKind::Inherited &&
conformance.getConcrete()->getType()->is<ArchetypeType>()) {
inheritedInterfaceType =
concreteConformance->getType()->mapTypeOutOfContext();
concreteConformance =
cast<InheritedProtocolConformance>(concreteConformance)
->getInheritedConformance();
}

// Map the conformance.
// FIXME: It would be so much easier and efficient if we had
// ProtocolConformance::mapTypesOutOfContext().
auto interfaceType =
conformance.getConcrete()->getType()->mapTypeOutOfContext();
concreteConformance->getType()->mapTypeOutOfContext();

conformance = *tc.conformsToProtocol(
interfaceType,
conformance.getRequirement(),
dc,
ConformanceCheckFlags::SuppressDependencyTracking);
interfaceType,
conformance.getRequirement(),
dc,
ConformanceCheckFlags::SuppressDependencyTracking);

// Reinstate inherited conformance.
if (inheritedInterfaceType) {
conformance =
ProtocolConformanceRef(
tc.Context.getInheritedConformance(inheritedInterfaceType,
conformance.getConcrete()));
}
}

writer(conformance);
Expand Down