@@ -263,6 +263,15 @@ ProtocolConformanceRef::getAssociatedConformance(Type conformingType,
263263 return conformance->getAssociatedConformance (assocType, protocol);
264264 }
265265
266+ auto computeSubjectType = [&](Type conformingType) -> Type {
267+ return assocType.transformRec (
268+ [&](TypeBase *t) -> std::optional<Type> {
269+ if (isa<GenericTypeParamType>(t))
270+ return conformingType;
271+ return std::nullopt ;
272+ });
273+ };
274+
266275 // An associated conformance of an archetype might be known to be
267276 // a concrete conformance, if the subject type is fixed to a concrete
268277 // type in the archetype's generic signature. We don't actually have
@@ -273,15 +282,8 @@ ProtocolConformanceRef::getAssociatedConformance(Type conformingType,
273282 // conformances where they store their subject types, we can also
274283 // cache the lookups inside the abstract conformance instance too.
275284 if (auto archetypeType = conformingType->getAs <ArchetypeType>()) {
276- conformingType = archetypeType->getInterfaceType ();
277285 auto *genericEnv = archetypeType->getGenericEnvironment ();
278-
279- auto subjectType = assocType.transformRec (
280- [&](TypeBase *t) -> std::optional<Type> {
281- if (isa<GenericTypeParamType>(t))
282- return conformingType;
283- return std::nullopt ;
284- });
286+ auto subjectType = computeSubjectType (archetypeType->getInterfaceType ());
285287
286288 return lookupConformance (
287289 genericEnv->mapTypeIntoContext (subjectType),
@@ -293,12 +295,8 @@ ProtocolConformanceRef::getAssociatedConformance(Type conformingType,
293295 // signature of the substitution (or in the case of type variables,
294296 // we have no visibility into constraints). See the parallel hack
295297 // to handle this in SubstitutionMap::lookupConformance().
296- CONDITIONAL_ASSERT (conformingType->isTypeParameter () ||
297- conformingType->isTypeVariableOrMember () ||
298- conformingType->is <UnresolvedType>() ||
299- conformingType->is <PlaceholderType>());
300-
301- return ProtocolConformanceRef::forAbstract (conformingType, protocol);
298+ auto subjectType = computeSubjectType (conformingType);
299+ return ProtocolConformanceRef::forAbstract (subjectType, protocol);
302300}
303301
304302// / Check of all types used by the conformance are canonical.
0 commit comments