@@ -100,7 +100,7 @@ static DeclContext *getEquivalentDeclContextFromSourceFile(DeclContext *DC,
100
100
if (!D)
101
101
return nullptr ;
102
102
auto *parentDC = newDC->getParent ();
103
- unsigned N;
103
+ unsigned N = ~ 0U ;
104
104
105
105
if (auto accessor = dyn_cast<AccessorDecl>(D)) {
106
106
// The AST for accessors is like:
@@ -140,22 +140,22 @@ static DeclContext *getEquivalentDeclContextFromSourceFile(DeclContext *DC,
140
140
newDC = SF;
141
141
do {
142
142
auto N = IndexStack.pop_back_val ();
143
- Decl *D;
143
+ Decl *D = nullptr ;
144
144
if (auto parentSF = dyn_cast<SourceFile>(newDC))
145
145
D = getElementAt (parentSF->getTopLevelDecls (), N);
146
146
else if (auto parentIDC = dyn_cast<IterableDeclContext>(newDC->getAsDecl ()))
147
147
D = getElementAt (parentIDC->getMembers (), N);
148
148
else
149
149
llvm_unreachable (" invalid DC kind for finding equivalent DC (query)" );
150
150
151
- if (auto storage = dyn_cast <AbstractStorageDecl>(D)) {
151
+ if (auto storage = dyn_cast_or_null <AbstractStorageDecl>(D)) {
152
152
if (IndexStack.empty ())
153
153
return nullptr ;
154
154
auto accessorN = IndexStack.pop_back_val ();
155
155
D = getElementAt (storage->getAllAccessors (), accessorN);
156
156
}
157
157
158
- newDC = dyn_cast <DeclContext>(D);
158
+ newDC = dyn_cast_or_null <DeclContext>(D);
159
159
if (!newDC)
160
160
return nullptr ;
161
161
} while (!IndexStack.empty ());
@@ -354,7 +354,7 @@ bool CompletionInstance::performCachedOperationIfPossible(
354
354
355
355
DeclContext *DC =
356
356
getEquivalentDeclContextFromSourceFile (newInfo.ParentContext , oldSF);
357
- if (!DC)
357
+ if (!DC || !isa<AbstractFunctionDecl>(DC) )
358
358
return false ;
359
359
360
360
// OK, we can perform fast completion for this. Update the orignal delayed
0 commit comments