@@ -263,6 +263,15 @@ ProtocolConformanceRef::getAssociatedConformance(Type conformingType,
263
263
return conformance->getAssociatedConformance (assocType, protocol);
264
264
}
265
265
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
+
266
275
// An associated conformance of an archetype might be known to be
267
276
// a concrete conformance, if the subject type is fixed to a concrete
268
277
// type in the archetype's generic signature. We don't actually have
@@ -273,15 +282,8 @@ ProtocolConformanceRef::getAssociatedConformance(Type conformingType,
273
282
// conformances where they store their subject types, we can also
274
283
// cache the lookups inside the abstract conformance instance too.
275
284
if (auto archetypeType = conformingType->getAs <ArchetypeType>()) {
276
- conformingType = archetypeType->getInterfaceType ();
277
285
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 ());
285
287
286
288
return lookupConformance (
287
289
genericEnv->mapTypeIntoContext (subjectType),
@@ -293,12 +295,8 @@ ProtocolConformanceRef::getAssociatedConformance(Type conformingType,
293
295
// signature of the substitution (or in the case of type variables,
294
296
// we have no visibility into constraints). See the parallel hack
295
297
// 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);
302
300
}
303
301
304
302
// / Check of all types used by the conformance are canonical.
0 commit comments