@@ -5321,49 +5321,41 @@ ASTContext::getOverrideGenericSignature(const NominalTypeDecl *baseNominal,
5321
5321
5322
5322
SmallVector<Requirement, 2 > addedRequirements;
5323
5323
5324
- if (isa<ProtocolDecl>(baseNominal)) {
5325
- assert (isa<ProtocolDecl>(derivedNominal));
5326
-
5327
- for (auto reqt : baseGenericSig.getRequirements ()) {
5328
- addedRequirements.push_back (reqt);
5324
+ unsigned derivedDepth = 0 ;
5325
+ unsigned baseDepth = 0 ;
5326
+ if (derivedNominalSig)
5327
+ derivedDepth = derivedNominalSig.getGenericParams ().back ()->getDepth () + 1 ;
5328
+ if (const auto baseNominalSig = baseNominal->getGenericSignature ())
5329
+ baseDepth = baseNominalSig.getGenericParams ().back ()->getDepth () + 1 ;
5330
+
5331
+ const auto subMap = derivedNominal->getDeclaredInterfaceType ()
5332
+ ->getContextSubstitutionMap (derivedNominal->getModuleContext (),
5333
+ baseNominal);
5334
+
5335
+ auto substFn = [&](SubstitutableType *type) -> Type {
5336
+ auto *gp = cast<GenericTypeParamType>(type);
5337
+
5338
+ if (gp->getDepth () < baseDepth) {
5339
+ return Type (gp).subst (subMap);
5329
5340
}
5330
- } else {
5331
- unsigned derivedDepth = 0 ;
5332
- unsigned baseDepth = 0 ;
5333
- if (derivedNominalSig)
5334
- derivedDepth = derivedNominalSig.getGenericParams ().back ()->getDepth () + 1 ;
5335
- if (const auto baseNominalSig = baseNominal->getGenericSignature ())
5336
- baseDepth = baseNominalSig.getGenericParams ().back ()->getDepth () + 1 ;
5337
-
5338
- const auto subMap = derivedNominal->getDeclaredInterfaceType ()
5339
- ->getContextSubstitutionMap (derivedNominal->getModuleContext (),
5340
- baseNominal);
5341
-
5342
- auto substFn = [&](SubstitutableType *type) -> Type {
5343
- auto *gp = cast<GenericTypeParamType>(type);
5344
-
5345
- if (gp->getDepth () < baseDepth) {
5346
- return Type (gp).subst (subMap);
5347
- }
5348
5341
5349
- return CanGenericTypeParamType::get (
5350
- gp->isTypeSequence (), gp->getDepth () - baseDepth + derivedDepth,
5351
- gp->getIndex (), *this );
5352
- };
5342
+ return CanGenericTypeParamType::get (
5343
+ gp->isTypeSequence (), gp->getDepth () - baseDepth + derivedDepth,
5344
+ gp->getIndex (), *this );
5345
+ };
5353
5346
5354
- auto lookupConformanceFn =
5355
- [&](CanType depTy, Type substTy,
5356
- ProtocolDecl *proto) -> ProtocolConformanceRef {
5357
- if (auto conf = subMap.lookupConformance (depTy, proto))
5358
- return conf;
5347
+ auto lookupConformanceFn =
5348
+ [&](CanType depTy, Type substTy,
5349
+ ProtocolDecl *proto) -> ProtocolConformanceRef {
5350
+ if (auto conf = subMap.lookupConformance (depTy, proto))
5351
+ return conf;
5359
5352
5360
- return ProtocolConformanceRef (proto);
5361
- };
5353
+ return ProtocolConformanceRef (proto);
5354
+ };
5362
5355
5363
- for (auto reqt : baseGenericSig.getRequirements ()) {
5364
- if (auto substReqt = reqt.subst (substFn, lookupConformanceFn)) {
5365
- addedRequirements.push_back (*substReqt);
5366
- }
5356
+ for (auto reqt : baseGenericSig.getRequirements ()) {
5357
+ if (auto substReqt = reqt.subst (substFn, lookupConformanceFn)) {
5358
+ addedRequirements.push_back (*substReqt);
5367
5359
}
5368
5360
}
5369
5361
0 commit comments