[Sema] Account for ExistentialType in lookupExistentialConformance.

This commit is contained in:
Holly Borla
2021-12-13 20:56:10 -08:00
parent cf4488922c
commit f368b77ad5

View File

@@ -978,13 +978,17 @@ ModuleDecl::lookupExistentialConformance(Type type, ProtocolDecl *protocol) {
// existential to an archetype parameter, so for now we restrict this to
// @objc protocols and marker protocols.
if (!layout.isObjC() && !protocol->isMarkerProtocol()) {
auto constraint = type;
if (auto existential = constraint->getAs<ExistentialType>())
constraint = existential->getConstraintType();
// There's a specific exception for protocols with self-conforming
// witness tables, but the existential has to be *exactly* that type.
// TODO: synthesize witness tables on-demand for protocol compositions
// that can satisfy the requirement.
if (protocol->requiresSelfConformanceWitnessTable() &&
type->is<ProtocolType>() &&
type->castTo<ProtocolType>()->getDecl() == protocol)
constraint->is<ProtocolType>() &&
constraint->castTo<ProtocolType>()->getDecl() == protocol)
return ProtocolConformanceRef(ctx.getSelfConformance(protocol));
return ProtocolConformanceRef::forInvalid();