@@ -7440,10 +7440,9 @@ swift::ide::makeCodeCompletionCallbacksFactory(
7440
7440
void swift::ide::lookupCodeCompletionResultsFromModule (
7441
7441
CodeCompletionResultSink &targetSink, const ModuleDecl *module ,
7442
7442
ArrayRef<std::string> accessPath, bool needLeadingDot,
7443
- const DeclContext *currDeclContext) {
7444
- // Consisitently use the SourceFile as the decl context, to avoid decl
7445
- // context specific behaviors.
7446
- auto *SF = currDeclContext->getParentSourceFile ();
7443
+ const SourceFile *SF) {
7444
+ // Use the SourceFile as the decl context, to avoid decl context specific
7445
+ // behaviors.
7447
7446
CompletionLookup Lookup (targetSink, module ->getASTContext (), SF);
7448
7447
Lookup.lookupExternalModuleDecls (module , accessPath, needLeadingDot);
7449
7448
}
@@ -7519,8 +7518,9 @@ void SimpleCachingCodeCompletionConsumer::handleResultsAndModules(
7519
7518
7520
7519
// Use the current SourceFile as the DeclContext so that we can use it to
7521
7520
// perform qualified lookup, and to get the correct visibility for
7522
- // @testable imports.
7523
- DeclContext *DCForModules = DC->getParentSourceFile ();
7521
+ // @testable imports. Also it cannot use 'DC' since it would apply decl
7522
+ // context changes to cached results.
7523
+ const SourceFile *SF = DC->getParentSourceFile ();
7524
7524
7525
7525
for (auto &R : requestedModules) {
7526
7526
// FIXME(thread-safety): lock the whole AST context. We might load a
@@ -7533,7 +7533,7 @@ void SimpleCachingCodeCompletionConsumer::handleResultsAndModules(
7533
7533
(*V)->Sink .annotateResult = context.getAnnotateResult ();
7534
7534
lookupCodeCompletionResultsFromModule (
7535
7535
(*V)->Sink , R.TheModule , R.Key .AccessPath ,
7536
- R.Key .ResultsHaveLeadingDot , DCForModules );
7536
+ R.Key .ResultsHaveLeadingDot , SF );
7537
7537
context.Cache .set (R.Key , *V);
7538
7538
}
7539
7539
assert (V.hasValue ());
0 commit comments