mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
AST: Allow ProtocolConformanceRef::getAssociatedType() with invalid conformance
This commit is contained in:
@@ -198,28 +198,40 @@ Type ProtocolConformanceRef::getAssociatedType(Type conformingType,
|
||||
Type assocType) const {
|
||||
if (isPack()) {
|
||||
auto *pack = getPack();
|
||||
assert(conformingType->isEqual(pack->getType()));
|
||||
ASSERT(conformingType->isEqual(pack->getType()));
|
||||
return pack->getAssociatedType(assocType);
|
||||
}
|
||||
|
||||
assert(!isConcrete() || getConcrete()->getType()->isEqual(conformingType));
|
||||
|
||||
auto type = assocType->getCanonicalType();
|
||||
auto proto = getRequirement();
|
||||
|
||||
// Fast path for generic parameters.
|
||||
if (isa<GenericTypeParamType>(type)) {
|
||||
assert(type->isEqual(proto->getSelfInterfaceType()) &&
|
||||
if (auto paramTy = dyn_cast<GenericTypeParamType>(type)) {
|
||||
ASSERT(paramTy->getDepth() == 0 && paramTy->getIndex() == 0 &&
|
||||
"type parameter in protocol was not Self");
|
||||
return conformingType;
|
||||
}
|
||||
|
||||
// Fast path for dependent member types on 'Self' of our associated types.
|
||||
auto memberType = cast<DependentMemberType>(type);
|
||||
if (memberType.getBase()->isEqual(proto->getSelfInterfaceType()) &&
|
||||
memberType->getAssocType()->getProtocol() == proto &&
|
||||
isConcrete())
|
||||
return getConcrete()->getTypeWitness(memberType->getAssocType());
|
||||
if (isInvalid())
|
||||
return ErrorType::get(assocType->getASTContext());
|
||||
|
||||
auto proto = getRequirement();
|
||||
|
||||
if (isConcrete()) {
|
||||
if (auto selfType = conformingType->getAs<DynamicSelfType>())
|
||||
conformingType = selfType->getSelfType();
|
||||
ASSERT(getConcrete()->getType()->isEqual(conformingType));
|
||||
|
||||
// Fast path for dependent member types on 'Self' of our associated types.
|
||||
auto memberType = cast<DependentMemberType>(type);
|
||||
if (memberType.getBase()->isEqual(proto->getSelfInterfaceType()) &&
|
||||
memberType->getAssocType()->getProtocol() == proto) {
|
||||
auto witnessType = getConcrete()->getTypeWitness(
|
||||
memberType->getAssocType());
|
||||
if (!witnessType)
|
||||
return ErrorType::get(assocType->getASTContext());
|
||||
return witnessType;
|
||||
}
|
||||
}
|
||||
|
||||
// General case: consult the substitution map.
|
||||
auto substMap =
|
||||
|
||||
Reference in New Issue
Block a user