@@ -126,6 +126,22 @@ class LookupVisibleDecls : public ModuleNameLookup<LookupVisibleDecls> {
126126
127127} // end anonymous namespace
128128
129+ bool swift::declIsVisibleToNameLookup (
130+ const ValueDecl *decl, const DeclContext *moduleScopeContext,
131+ NLOptions options) {
132+ // NL_IgnoreAccessControl only applies to the current module. If
133+ // it applies here, the declaration is visible.
134+ if ((options & NL_IgnoreAccessControl) &&
135+ moduleScopeContext &&
136+ moduleScopeContext->getParentModule () ==
137+ decl->getDeclContext ()->getParentModule ())
138+ return true ;
139+
140+ bool includeUsableFromInline = options & NL_IncludeUsableFromInline;
141+ return decl->isAccessibleFrom (moduleScopeContext, false ,
142+ includeUsableFromInline);
143+ }
144+
129145template <typename LookupStrategy>
130146void ModuleNameLookup<LookupStrategy>::lookupInModule(
131147 SmallVectorImpl<ValueDecl *> &decls,
@@ -151,7 +167,6 @@ void ModuleNameLookup<LookupStrategy>::lookupInModule(
151167
152168 const size_t initialCount = decls.size ();
153169 size_t currentCount = decls.size ();
154- bool includeUsableFromInline = options & NL_IncludeUsableFromInline;
155170
156171 auto updateNewDecls = [&](const DeclContext *moduleScopeContext) {
157172 if (decls.size () == currentCount)
@@ -165,13 +180,7 @@ void ModuleNameLookup<LookupStrategy>::lookupInModule(
165180 if (resolutionKind == ResolutionKind::MacrosOnly && !isa<MacroDecl>(VD))
166181 return true ;
167182 if (respectAccessControl &&
168- // NL_IgnoreAccessControl applies only to the current module.
169- !((options & NL_IgnoreAccessControl) &&
170- moduleScopeContext &&
171- moduleScopeContext->getParentModule () ==
172- VD->getDeclContext ()->getParentModule ()) &&
173- !VD->isAccessibleFrom (moduleScopeContext, false ,
174- includeUsableFromInline))
183+ !declIsVisibleToNameLookup (VD, moduleScopeContext, options))
175184 return true ;
176185 return false ;
177186 });
0 commit comments