20
20
#include " swift/AST/TypeWalker.h"
21
21
#include " swift/AST/Decl.h"
22
22
#include " swift/AST/AST.h"
23
+ #include " swift/AST/GenericEnvironment.h"
23
24
#include " swift/AST/LazyResolver.h"
24
25
#include " swift/AST/Module.h"
25
26
#include " swift/AST/SubstitutionMap.h"
@@ -3240,7 +3241,7 @@ TypeSubstitutionMap TypeBase::getContextSubstitutions(const DeclContext *dc) {
3240
3241
}
3241
3242
3242
3243
SubstitutionMap TypeBase::getContextSubstitutionMap (
3243
- ModuleDecl *module , const DeclContext *dc) {
3244
+ ModuleDecl *module , const DeclContext *dc) {
3244
3245
auto *genericSig = dc->getGenericSignatureOfContext ();
3245
3246
if (genericSig == nullptr )
3246
3247
return SubstitutionMap ();
@@ -3249,7 +3250,9 @@ SubstitutionMap TypeBase::getContextSubstitutionMap(
3249
3250
LookUpConformanceInModule (module ));
3250
3251
}
3251
3252
3252
- TypeSubstitutionMap TypeBase::getMemberSubstitutions (const ValueDecl *member) {
3253
+ TypeSubstitutionMap TypeBase::getMemberSubstitutions (
3254
+ const ValueDecl *member,
3255
+ GenericEnvironment *genericEnv) {
3253
3256
auto *memberDC = member->getDeclContext ();
3254
3257
3255
3258
TypeSubstitutionMap substitutions;
@@ -3262,14 +3265,18 @@ TypeSubstitutionMap TypeBase::getMemberSubstitutions(const ValueDecl *member) {
3262
3265
// We need this since code completion and diagnostics want to be able
3263
3266
// to call getTypeOfMember() with functions and nested types.
3264
3267
if (isa<AbstractFunctionDecl>(member) ||
3265
- isa<GenericTypeDecl>(member)) {
3268
+ isa<GenericTypeDecl>(member) ||
3269
+ isa<SubscriptDecl>(member)) {
3266
3270
auto *innerDC = member->getInnermostDeclContext ();
3267
3271
if (innerDC->isInnermostContextGeneric ()) {
3268
3272
auto *sig = innerDC->getGenericSignatureOfContext ();
3269
3273
for (auto param : sig->getInnermostGenericParams ()) {
3270
3274
auto *genericParam = param->getCanonicalType ()
3271
3275
->castTo <GenericTypeParamType>();
3272
- substitutions[genericParam] = param;
3276
+ substitutions[genericParam] =
3277
+ (genericEnv
3278
+ ? genericEnv->mapTypeIntoContext (param)
3279
+ : param);
3273
3280
}
3274
3281
}
3275
3282
}
@@ -3278,13 +3285,15 @@ TypeSubstitutionMap TypeBase::getMemberSubstitutions(const ValueDecl *member) {
3278
3285
}
3279
3286
3280
3287
SubstitutionMap TypeBase::getMemberSubstitutionMap (
3281
- ModuleDecl *module , const ValueDecl *member) {
3288
+ ModuleDecl *module , const ValueDecl *member,
3289
+ GenericEnvironment *genericEnv) {
3282
3290
auto *genericSig = member->getInnermostDeclContext ()
3283
3291
->getGenericSignatureOfContext ();
3284
3292
if (genericSig == nullptr )
3285
3293
return SubstitutionMap ();
3294
+ auto subs = getMemberSubstitutions (member, genericEnv);
3286
3295
return genericSig->getSubstitutionMap (
3287
- QueryTypeSubstitutionMap{getMemberSubstitutions (member) },
3296
+ QueryTypeSubstitutionMap{subs },
3288
3297
LookUpConformanceInModule (module ));
3289
3298
}
3290
3299
0 commit comments