@@ -324,10 +324,17 @@ struct SynthesizedExtensionAnalyzer::Implementation {
324324 return {Result, MergeInfo};
325325 }
326326
327- auto handleRequirements = [&](SubstitutionMap subMap,
328- ExtensionDecl *OwningExt,
327+ auto handleRequirements = [&](ExtensionDecl *OwningExt,
329328 ArrayRef<Requirement> Reqs) {
330329 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+ }
331338 for (auto Req : Reqs) {
332339 // Skip protocol's Self : <Protocol> requirement.
333340 if (BaseProto &&
@@ -336,7 +343,7 @@ struct SynthesizedExtensionAnalyzer::Implementation {
336343 Req.getProtocolDecl () == BaseProto)
337344 continue ;
338345
339- if (!BaseType-> isExistentialType () ) {
346+ if (subMap ) {
340347 // Apply any substitutions we need to map the requirements from a
341348 // a protocol extension to an extension on the conforming type. We
342349 // need to lookup conformances outside of the substitution map since
@@ -395,30 +402,14 @@ struct SynthesizedExtensionAnalyzer::Implementation {
395402 };
396403
397404 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-
407405 assert (Ext->getGenericSignature () && " No generic signature." );
408406 auto GenericSig = Ext->getGenericSignature ();
409- if (handleRequirements (subMap, Ext, GenericSig.getRequirements ()))
407+ if (handleRequirements (Ext, GenericSig.getRequirements ()))
410408 return {Result, MergeInfo};
411409 }
412410
413411 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 ()))
422413 return {Result, MergeInfo};
423414 }
424415
0 commit comments