@@ -212,19 +212,9 @@ void AccessControlCheckerBase::checkTypeAccessImpl(
212
212
// Report where it was imported from.
213
213
if (contextAccessScope.isPublicOrPackage ()) {
214
214
auto report = [&](const DeclRefTypeRepr *typeRepr, const ValueDecl *VD) {
215
- // Remember that the module defining the decl must be imported publicly.
215
+ SourceLoc diagLoc = typeRepr ? typeRepr-> getLoc () : SourceLoc ();
216
216
recordRequiredImportAccessLevelForDecl (
217
- VD, useDC, contextAccessScope.accessLevelForDiagnostics (),
218
- [&](AttributedImport<ImportedModule> attributedImport) {
219
- SourceLoc diagLoc =
220
- typeRepr ? typeRepr->getLoc () : extractNearestSourceLoc (useDC);
221
- ModuleDecl *importedVia = attributedImport.module .importedModule ,
222
- *sourceModule = VD->getModuleContext ();
223
- Context.Diags .diagnose (diagLoc, diag::module_api_import, VD,
224
- importedVia, sourceModule,
225
- importedVia == sourceModule,
226
- /* isImplicit*/ !typeRepr);
227
- });
217
+ VD, useDC, contextAccessScope.accessLevelForDiagnostics (), diagLoc);
228
218
};
229
219
230
220
if (typeRepr) {
@@ -2445,15 +2435,8 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
2445
2435
2446
2436
// Remember that the module defining the extended type must be imported
2447
2437
// publicly.
2448
- recordRequiredImportAccessLevelForDecl (
2449
- extendedType, DC, AccessLevel::Public,
2450
- [&](AttributedImport<ImportedModule> attributedImport) {
2451
- ModuleDecl *importedVia = attributedImport.module .importedModule ,
2452
- *sourceModule = ED->getModuleContext ();
2453
- ED->diagnose (diag::module_api_import, ED, importedVia, sourceModule,
2454
- importedVia == sourceModule,
2455
- /* isImplicit*/ false );
2456
- });
2438
+ recordRequiredImportAccessLevelForDecl (extendedType, DC,
2439
+ AccessLevel::Public, ED->getLoc ());
2457
2440
}
2458
2441
}
2459
2442
@@ -2579,6 +2562,23 @@ void swift::recordRequiredImportAccessLevelForDecl(
2579
2562
}
2580
2563
}
2581
2564
2565
+ void swift::recordRequiredImportAccessLevelForDecl (const ValueDecl *decl,
2566
+ const DeclContext *dc,
2567
+ AccessLevel accessLevel,
2568
+ SourceLoc loc) {
2569
+ recordRequiredImportAccessLevelForDecl (
2570
+ decl, dc, accessLevel,
2571
+ [&](AttributedImport<ImportedModule> attributedImport) {
2572
+ SourceLoc diagLoc =
2573
+ loc.isValid () ? loc : extractNearestSourceLoc (dc);
2574
+ ModuleDecl *importedVia = attributedImport.module .importedModule ,
2575
+ *sourceModule = decl->getModuleContext ();
2576
+ dc->getASTContext ().Diags .diagnose (
2577
+ diagLoc, diag::module_api_import, decl, importedVia, sourceModule,
2578
+ importedVia == sourceModule, loc.isInvalid ());
2579
+ });
2580
+ }
2581
+
2582
2582
void swift::diagnoseUnnecessaryPublicImports (SourceFile &SF) {
2583
2583
ASTContext &ctx = SF.getASTContext ();
2584
2584
if (ctx.TypeCheckerOpts .SkipFunctionBodies != FunctionBodySkipping::None)
@@ -2649,15 +2649,8 @@ void registerPackageAccessForPackageExtendedType(ExtensionDecl *ED) {
2649
2649
2650
2650
// Remember that the module defining the decl must be imported with at least
2651
2651
// package visibility.
2652
- recordRequiredImportAccessLevelForDecl (
2653
- extendedType, DC, AccessLevel::Package,
2654
- [&](AttributedImport<ImportedModule> attributedImport) {
2655
- ModuleDecl *importedVia = attributedImport.module .importedModule ,
2656
- *sourceModule = ED->getModuleContext ();
2657
- ED->diagnose (diag::module_api_import, ED, importedVia, sourceModule,
2658
- importedVia == sourceModule,
2659
- /* isImplicit*/ false );
2660
- });
2652
+ recordRequiredImportAccessLevelForDecl (extendedType, DC, AccessLevel::Package,
2653
+ ED->getLoc ());
2661
2654
}
2662
2655
2663
2656
void swift::checkAccessControl (Decl *D) {
0 commit comments