Skip to content

Commit 0f072b4

Browse files
committed
IDE: Clean up isMemberDeclAppliedInternal()
In preparation for checkRequirements() asserting upon encountering type parameters. Should be NFC.
1 parent a7f484b commit 0f072b4

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

lib/IDE/CompletionLookup.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,8 @@ Type CompletionLookup::getTypeOfMember(const ValueDecl *VD,
637637
// τ_1_0(U) => U }
638638
auto subs = keyPathInfo.baseType->getMemberSubstitutions(SD);
639639

640+
// FIXME: The below should use substitution map substitution.
641+
640642
// If the keyPath result type has type parameters, that might affect the
641643
// subscript result type.
642644
auto keyPathResultTy =

lib/Sema/IDETypeCheckingRequests.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

180194
bool

0 commit comments

Comments
 (0)