Skip to content

Commit 872ceea

Browse files
committed
Allow a specialized conformance to fail
This handles the case where a conditional conformance cannot be inherited because the subclass provides a generic argument that doesn't satisfy the conditional requirements. https://bugs.swift.org/browse/SR-7337
1 parent 8199e8d commit 872ceea

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

lib/AST/ASTContext.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,12 @@ ASTContext::getSpecializedConformance(Type type,
18911891
if (auto *genericSig = generic->getGenericSignature())
18921892
genericSig->getSubstitutions(subMap, subs);
18931893

1894+
bool anyError = llvm::any_of(subs, [](const Substitution &sub) {
1895+
return sub.getReplacement()->hasError();
1896+
});
1897+
if (anyError)
1898+
return nullptr;
1899+
18941900
return getSpecializedConformance(type, generic, subs,
18951901
/*alreadyCheckedCollapsed=*/true);
18961902
}

lib/AST/ConformanceLookupTable.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,8 @@ ConformanceLookupTable::getConformance(NominalTypeDecl *nominal,
851851
ModuleDecl *module = entry->getDeclContext()->getParentModule();
852852
auto inheritedConformance = module->lookupConformance(superclassTy,
853853
protocol);
854+
if (!inheritedConformance)
855+
return nullptr;
854856

855857
// Form the inherited conformance.
856858
entry->Conformance =

lib/AST/Module.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,11 @@ ModuleDecl::lookupConformance(Type type, ProtocolDecl *protocol) {
689689
auto subMap = type->getContextSubstitutionMap(this, explicitConformanceDC);
690690

691691
// Create the specialized conformance entry.
692-
auto result = ctx.getSpecializedConformance(type, conformance, subMap);
693-
return ProtocolConformanceRef(result);
692+
if (auto result = ctx.getSpecializedConformance(type, conformance,
693+
subMap)) {
694+
return ProtocolConformanceRef(result);
695+
}
696+
return None;
694697
}
695698
}
696699

0 commit comments

Comments
 (0)