@@ -161,20 +161,34 @@ static bool isMemberDeclAppliedInternal(const DeclContext *DC, Type BaseTy,
161
161
const GenericContext *genericDecl = VD->getAsGenericContext ();
162
162
if (!genericDecl)
163
163
return true ;
164
+
165
+ // The declaration may introduce inner generic parameters and requirements,
166
+ // or it may be nested in an outer generic context.
164
167
GenericSignature genericSig = genericDecl->getGenericSignature ();
165
168
if (!genericSig)
166
169
return true ;
167
170
171
+ // The context substitution map for the base type fixes the declaration's
172
+ // outer generic parameters.
168
173
auto *module = DC->getParentModule ();
169
- SubstitutionMap substMap = BaseTy->getContextSubstitutionMap (
174
+ auto substMap = BaseTy->getContextSubstitutionMap (
170
175
module , VD->getDeclContext ());
171
176
172
- // Note: we treat substitution failure as success, to avoid tripping
173
- // up over generic parameters introduced by the declaration itself.
177
+ // The innermost generic parameters are mapped to error types.
178
+ unsigned innerDepth = genericSig.getGenericParams ().back ()->getDepth ();
179
+ if (!genericDecl->isGeneric ())
180
+ ++innerDepth;
181
+
182
+ // We treat substitution failure as success, to ignore requirements
183
+ // that involve innermost generic parameters.
174
184
return checkRequirements (module ,
175
185
genericSig.getRequirements (),
176
- QuerySubstitutionMap{substMap}) !=
177
- CheckRequirementsResult::RequirementFailure;
186
+ [&](SubstitutableType *type) -> Type {
187
+ auto *paramTy = cast<GenericTypeParamType>(type);
188
+ if (paramTy->getDepth () == innerDepth)
189
+ return ErrorType::get (DC->getASTContext ());
190
+ return Type (paramTy).subst (substMap);
191
+ }) != CheckRequirementsResult::RequirementFailure;
178
192
}
179
193
180
194
bool
0 commit comments