@@ -7440,10 +7440,9 @@ swift::ide::makeCodeCompletionCallbacksFactory(
74407440void swift::ide::lookupCodeCompletionResultsFromModule (
74417441 CodeCompletionResultSink &targetSink, const ModuleDecl *module ,
74427442 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.
74477446 CompletionLookup Lookup (targetSink, module ->getASTContext (), SF);
74487447 Lookup.lookupExternalModuleDecls (module , accessPath, needLeadingDot);
74497448}
@@ -7519,8 +7518,9 @@ void SimpleCachingCodeCompletionConsumer::handleResultsAndModules(
75197518
75207519 // Use the current SourceFile as the DeclContext so that we can use it to
75217520 // 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 ();
75247524
75257525 for (auto &R : requestedModules) {
75267526 // FIXME(thread-safety): lock the whole AST context. We might load a
@@ -7533,7 +7533,7 @@ void SimpleCachingCodeCompletionConsumer::handleResultsAndModules(
75337533 (*V)->Sink .annotateResult = context.getAnnotateResult ();
75347534 lookupCodeCompletionResultsFromModule (
75357535 (*V)->Sink , R.TheModule , R.Key .AccessPath ,
7536- R.Key .ResultsHaveLeadingDot , DCForModules );
7536+ R.Key .ResultsHaveLeadingDot , SF );
75377537 context.Cache .set (R.Key , *V);
75387538 }
75397539 assert (V.hasValue ());
0 commit comments