@@ -324,10 +324,17 @@ struct SynthesizedExtensionAnalyzer::Implementation {
324
324
return {Result, MergeInfo};
325
325
}
326
326
327
- auto handleRequirements = [&](SubstitutionMap subMap,
328
- ExtensionDecl *OwningExt,
327
+ auto handleRequirements = [&](ExtensionDecl *OwningExt,
329
328
ArrayRef<Requirement> Reqs) {
330
329
ProtocolDecl *BaseProto = OwningExt->getSelfProtocolDecl ();
330
+ // Get the substitutions from the generic signature of
331
+ // the extension to the interface types of the base type's
332
+ // declaration.
333
+ SubstitutionMap subMap;
334
+ if (!BaseType->is <ProtocolType>()) {
335
+ if (auto *NTD = OwningExt->getExtendedNominal ())
336
+ subMap = BaseType->getContextSubstitutionMap (NTD);
337
+ }
331
338
for (auto Req : Reqs) {
332
339
// Skip protocol's Self : <Protocol> requirement.
333
340
if (BaseProto &&
@@ -336,7 +343,7 @@ struct SynthesizedExtensionAnalyzer::Implementation {
336
343
Req.getProtocolDecl () == BaseProto)
337
344
continue ;
338
345
339
- if (!BaseType-> isExistentialType () ) {
346
+ if (subMap ) {
340
347
// Apply any substitutions we need to map the requirements from a
341
348
// a protocol extension to an extension on the conforming type. We
342
349
// need to lookup conformances outside of the substitution map since
@@ -395,30 +402,14 @@ struct SynthesizedExtensionAnalyzer::Implementation {
395
402
};
396
403
397
404
if (Ext->isConstrainedExtension ()) {
398
- // Get the substitutions from the generic signature of
399
- // the extension to the interface types of the base type's
400
- // declaration.
401
- SubstitutionMap subMap;
402
- if (!BaseType->isExistentialType ()) {
403
- if (auto *NTD = Ext->getExtendedNominal ())
404
- subMap = BaseType->getContextSubstitutionMap (NTD);
405
- }
406
-
407
405
assert (Ext->getGenericSignature () && " No generic signature." );
408
406
auto GenericSig = Ext->getGenericSignature ();
409
- if (handleRequirements (subMap, Ext, GenericSig.getRequirements ()))
407
+ if (handleRequirements (Ext, GenericSig.getRequirements ()))
410
408
return {Result, MergeInfo};
411
409
}
412
410
413
411
if (Conf) {
414
- SubstitutionMap subMap;
415
- if (!BaseType->isExistentialType ()) {
416
- if (auto *NTD = EnablingExt->getExtendedNominal ())
417
- subMap = BaseType->getContextSubstitutionMap (NTD);
418
- }
419
- if (handleRequirements (subMap,
420
- EnablingExt,
421
- Conf->getConditionalRequirements ()))
412
+ if (handleRequirements (EnablingExt, Conf->getConditionalRequirements ()))
422
413
return {Result, MergeInfo};
423
414
}
424
415
0 commit comments