27
27
#include " swift/AST/ASTContext.h"
28
28
#include " swift/AST/Decl.h"
29
29
#include " swift/AST/GenericEnvironment.h"
30
+ #include " swift/AST/GenericParamList.h"
30
31
#include " swift/AST/LazyResolver.h"
31
32
#include " swift/AST/Module.h"
32
33
#include " swift/AST/ProtocolConformance.h"
@@ -510,18 +511,23 @@ SubstitutionMap::getOverrideSubstitutions(
510
511
511
512
auto baseSig = baseDecl->getInnermostDeclContext ()
512
513
->getGenericSignatureOfContext ();
513
- auto derivedSig = derivedDecl->getInnermostDeclContext ()
514
- ->getGenericSignatureOfContext ();
515
514
516
- return getOverrideSubstitutions (baseClass, derivedClass,
517
- baseSig, derivedSig);
515
+ // If more kinds of overridable decls with generic parameter lists appear,
516
+ // add them here.
517
+ GenericParamList *derivedParams = nullptr ;
518
+ if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(derivedDecl))
519
+ derivedParams = funcDecl->getGenericParams ();
520
+ else if (auto *subscriptDecl = dyn_cast<SubscriptDecl>(derivedDecl))
521
+ derivedParams = subscriptDecl->getGenericParams ();
522
+
523
+ return getOverrideSubstitutions (baseClass, derivedClass, baseSig, derivedParams);
518
524
}
519
525
520
526
SubstitutionMap
521
527
SubstitutionMap::getOverrideSubstitutions (const ClassDecl *baseClass,
522
528
const ClassDecl *derivedClass,
523
529
GenericSignature baseSig,
524
- GenericSignature derivedSig ) {
530
+ GenericParamList *derivedParams ) {
525
531
if (baseSig.isNull ())
526
532
return SubstitutionMap ();
527
533
@@ -547,10 +553,14 @@ SubstitutionMap::getOverrideSubstitutions(const ClassDecl *baseClass,
547
553
if (auto gp = type->getAs <GenericTypeParamType>()) {
548
554
if (gp->getDepth () >= baseDepth) {
549
555
assert (gp->getDepth () == baseDepth);
550
- auto substGP = GenericTypeParamType::get (gp->isTypeSequence (),
551
- gp->getDepth () + origDepth - baseDepth,
552
- gp->getIndex (), ctx);
553
- return derivedSig->getSugaredType (substGP);
556
+ if (derivedParams != nullptr ) {
557
+ return derivedParams->getParams ()[gp->getIndex ()]
558
+ ->getDeclaredInterfaceType ();
559
+ }
560
+
561
+ return GenericTypeParamType::get (gp->isTypeSequence (),
562
+ gp->getDepth () + origDepth - baseDepth,
563
+ gp->getIndex (), ctx);
554
564
}
555
565
}
556
566
0 commit comments