AST: Add ProtocolConformanceRef::getTypeWitness()

This commit is contained in:
Slava Pestov
2024-09-18 11:36:25 -04:00
parent a27d6cf741
commit 508dacc3a2
2 changed files with 46 additions and 0 deletions

View File

@@ -194,6 +194,47 @@ ProtocolConformanceRef::getConditionalRequirements() const {
return {};
}
Type ProtocolConformanceRef::getTypeWitness(Type conformingType,
AssociatedTypeDecl *assocType,
SubstOptions options) const {
if (isPack()) {
auto *pack = getPack();
ASSERT(conformingType->isEqual(pack->getType()));
return pack->getAssociatedType(assocType->getDeclaredInterfaceType());
}
auto failed = [&]() {
return DependentMemberType::get(ErrorType::get(conformingType),
assocType);
};
if (isInvalid())
return failed();
auto proto = getRequirement();
ASSERT(assocType->getProtocol() == proto);
if (isConcrete()) {
auto witnessType = getConcrete()->getTypeWitness(assocType, options);
if (!witnessType || witnessType->is<ErrorType>())
return failed();
return witnessType;
}
ASSERT(isAbstract());
if (auto *archetypeType = conformingType->getAs<ArchetypeType>()) {
return archetypeType->getNestedType(assocType);
}
CONDITIONAL_ASSERT(conformingType->isTypeParameter() ||
conformingType->isTypeVariableOrMember() ||
conformingType->is<UnresolvedType>() ||
conformingType->is<PlaceholderType>());
return DependentMemberType::get(conformingType, assocType);
}
Type ProtocolConformanceRef::getAssociatedType(Type conformingType,
Type assocType) const {
if (isPack()) {