Skip to content

Commit 7c2c34f

Browse files
committed
IDE: Fix a usage of lookupVisibleMemberDecls() to not pass in an existential type
It's better to use the 'Self' archetype here.
1 parent 6c2d511 commit 7c2c34f

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4177,13 +4177,12 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
41774177
}
41784178
}
41794179

4180-
void addDesignatedInitializers(Type CurrTy) {
4180+
void addDesignatedInitializers(NominalTypeDecl *NTD) {
41814181
if (hasFuncIntroducer || hasVarIntroducer || hasTypealiasIntroducer ||
41824182
hasOverridabilityModifier)
41834183
return;
41844184

4185-
assert(CurrTy);
4186-
const auto *CD = dyn_cast_or_null<ClassDecl>(CurrTy->getAnyNominal());
4185+
const auto *CD = dyn_cast<ClassDecl>(NTD);
41874186
if (!CD)
41884187
return;
41894188
if (!CD->hasSuperclass())
@@ -4200,14 +4199,12 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
42004199
}
42014200
}
42024201

4203-
void addAssociatedTypes(Type CurrTy) {
4202+
void addAssociatedTypes(NominalTypeDecl *NTD) {
42044203
if (!hasTypealiasIntroducer &&
42054204
(hasFuncIntroducer || hasVarIntroducer || hasInitializerModifier ||
42064205
hasOverride || hasOverridabilityModifier))
42074206
return;
42084207

4209-
NominalTypeDecl *NTD = CurrTy->getAnyNominal();
4210-
42114208
for (auto Conformance : NTD->getAllConformances()) {
42124209
auto Proto = Conformance->getProtocol();
42134210
if (!Proto->isAccessibleFrom(CurrDeclContext))
@@ -4233,13 +4230,14 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
42334230
if (isa<ProtocolDecl>(CurrDeclContext))
42344231
return;
42354232

4236-
Type CurrTy = CurrDeclContext->getDeclaredTypeInContext();
4233+
Type CurrTy = CurrDeclContext->getSelfTypeInContext();
4234+
auto *NTD = CurrDeclContext->getSelfNominalTypeDecl();
42374235
if (CurrTy && !CurrTy->is<ErrorType>()) {
42384236
lookupVisibleMemberDecls(*this, CurrTy, CurrDeclContext,
42394237
TypeResolver,
42404238
/*includeInstanceMembers=*/false);
4241-
addDesignatedInitializers(CurrTy);
4242-
addAssociatedTypes(CurrTy);
4239+
addDesignatedInitializers(NTD);
4240+
addAssociatedTypes(NTD);
42434241
}
42444242
}
42454243
};

0 commit comments

Comments
 (0)