@@ -7418,10 +7418,9 @@ swift::ide::makeCodeCompletionCallbacksFactory(
7418
7418
void swift::ide::lookupCodeCompletionResultsFromModule (
7419
7419
CodeCompletionResultSink &targetSink, const ModuleDecl *module ,
7420
7420
ArrayRef<std::string> accessPath, bool needLeadingDot,
7421
- const DeclContext *currDeclContext) {
7422
- // Consisitently use the SourceFile as the decl context, to avoid decl
7423
- // context specific behaviors.
7424
- auto *SF = currDeclContext->getParentSourceFile ();
7421
+ const SourceFile *SF) {
7422
+ // Use the SourceFile as the decl context, to avoid decl context specific
7423
+ // behaviors.
7425
7424
CompletionLookup Lookup (targetSink, module ->getASTContext (), SF);
7426
7425
Lookup.lookupExternalModuleDecls (module , accessPath, needLeadingDot);
7427
7426
}
@@ -7497,8 +7496,9 @@ void SimpleCachingCodeCompletionConsumer::handleResultsAndModules(
7497
7496
7498
7497
// Use the current SourceFile as the DeclContext so that we can use it to
7499
7498
// perform qualified lookup, and to get the correct visibility for
7500
- // @testable imports.
7501
- DeclContext *DCForModules = DC->getParentSourceFile ();
7499
+ // @testable imports. Also it cannot use 'DC' since it would apply decl
7500
+ // context changes to cached results.
7501
+ const SourceFile *SF = DC->getParentSourceFile ();
7502
7502
7503
7503
for (auto &R : requestedModules) {
7504
7504
// FIXME(thread-safety): lock the whole AST context. We might load a
@@ -7511,7 +7511,7 @@ void SimpleCachingCodeCompletionConsumer::handleResultsAndModules(
7511
7511
(*V)->Sink .annotateResult = context.getAnnotateResult ();
7512
7512
lookupCodeCompletionResultsFromModule (
7513
7513
(*V)->Sink , R.TheModule , R.Key .AccessPath ,
7514
- R.Key .ResultsHaveLeadingDot , DCForModules );
7514
+ R.Key .ResultsHaveLeadingDot , SF );
7515
7515
context.Cache .set (R.Key , *V);
7516
7516
}
7517
7517
assert (V.hasValue ());
0 commit comments