@@ -349,16 +349,27 @@ GenericEnvironment::getOrCreateArchetypeFromInterfaceType(Type depType) {
349
349
350
350
case Kind::OpenedExistential: {
351
351
// FIXME: The existential layout's protocols might differ from the
352
- // canonicalized set of protocols determined by the generic signature,
353
- // so use the existential layout's version. We should align these at
352
+ // canonicalized set of protocols determined by the generic signature.
353
+ // Before NestedArchetypeType was removed, we used the former when
354
+ // building a root OpenedArchetypeType, and the latter when building
355
+ // nested archetypes.
356
+ // For compatibility, continue using the existential layout's version when
357
+ // the interface type is a generic parameter. We should align these at
354
358
// some point.
355
- auto layout = getOpenedExistentialType ()->getExistentialLayout ();
356
- SmallVector<ProtocolDecl *, 4 > protos;
357
- for (auto protoType : layout.getProtocols ())
358
- protos.push_back (protoType->getDecl ());
359
- result = OpenedArchetypeType::getNew (this , requirements.anchor ,
360
- protos, superclass,
361
- requirements.layout );
359
+ if (depType->is <GenericTypeParamType>()) {
360
+ auto layout = getOpenedExistentialType ()->getExistentialLayout ();
361
+ SmallVector<ProtocolDecl *, 2 > protos;
362
+ for (auto protoType : layout.getProtocols ())
363
+ protos.push_back (protoType->getDecl ());
364
+
365
+ result = OpenedArchetypeType::getNew (this , requirements.anchor , protos,
366
+ superclass, requirements.layout );
367
+ } else {
368
+ result = OpenedArchetypeType::getNew (this , requirements.anchor ,
369
+ requirements.protos , superclass,
370
+ requirements.layout );
371
+ }
372
+
362
373
break ;
363
374
}
364
375
0 commit comments