@@ -2259,6 +2259,48 @@ void NominalTypeDecl::recordObjCMethod(AbstractFunctionDecl *method,
2259
2259
vec.push_back (method);
2260
2260
}
2261
2261
2262
+ static bool missingExplicitImportForMemberDecl (const DeclContext *dc,
2263
+ ValueDecl *decl) {
2264
+ // Only require explicit imports for members when MemberImportVisibility is
2265
+ // enabled.
2266
+ if (!dc->getASTContext ().LangOpts .hasFeature (Feature::MemberImportVisibility))
2267
+ return false ;
2268
+
2269
+ // If the decl is in the same module, no import is required.
2270
+ auto declModule = decl->getDeclContext ()->getParentModule ();
2271
+ if (declModule == dc->getParentModule ())
2272
+ return false ;
2273
+
2274
+ // Source files are not expected to contain an import for the clang header
2275
+ // module.
2276
+ if (auto *loader = dc->getASTContext ().getClangModuleLoader ()) {
2277
+ if (declModule == loader->getImportedHeaderModule ())
2278
+ return false ;
2279
+ }
2280
+
2281
+ // Only require an import in the context of user authored source file.
2282
+ auto sf = dc->getParentSourceFile ();
2283
+ if (!sf)
2284
+ return false ;
2285
+
2286
+ switch (sf->Kind ) {
2287
+ case SourceFileKind::SIL:
2288
+ case SourceFileKind::Interface:
2289
+ case SourceFileKind::MacroExpansion:
2290
+ case SourceFileKind::DefaultArgument:
2291
+ return false ;
2292
+ case SourceFileKind::Library:
2293
+ case SourceFileKind::Main:
2294
+ break ;
2295
+ }
2296
+
2297
+ // If we've found an import, we're done.
2298
+ if (decl->findImport (dc))
2299
+ return false ;
2300
+
2301
+ return true ;
2302
+ }
2303
+
2262
2304
// / Determine whether the given declaration is an acceptable lookup
2263
2305
// / result when searching from the given DeclContext.
2264
2306
static bool isAcceptableLookupResult (const DeclContext *dc,
@@ -2291,10 +2333,7 @@ static bool isAcceptableLookupResult(const DeclContext *dc,
2291
2333
2292
2334
// Check that there is some import in the originating context that
2293
2335
// makes this decl visible.
2294
- if (decl->getDeclContext ()->getParentModule () != dc->getParentModule () &&
2295
- dc->getASTContext ().LangOpts .hasFeature (
2296
- Feature::MemberImportVisibility) &&
2297
- !decl->findImport (dc))
2336
+ if (missingExplicitImportForMemberDecl (dc, decl))
2298
2337
return false ;
2299
2338
}
2300
2339
0 commit comments