@@ -161,20 +161,34 @@ static bool isMemberDeclAppliedInternal(const DeclContext *DC, Type BaseTy,
161161 const GenericContext *genericDecl = VD->getAsGenericContext ();
162162 if (!genericDecl)
163163 return true ;
164+
165+ // The declaration may introduce inner generic parameters and requirements,
166+ // or it may be nested in an outer generic context.
164167 GenericSignature genericSig = genericDecl->getGenericSignature ();
165168 if (!genericSig)
166169 return true ;
167170
171+ // The context substitution map for the base type fixes the declaration's
172+ // outer generic parameters.
168173 auto *module = DC->getParentModule ();
169- SubstitutionMap substMap = BaseTy->getContextSubstitutionMap (
174+ auto substMap = BaseTy->getContextSubstitutionMap (
170175 module , VD->getDeclContext ());
171176
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.
174184 return checkRequirements (module ,
175185 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;
178192}
179193
180194bool
0 commit comments