@@ -60,8 +60,27 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
6060 if (D->getDeclContext ()->isLocalContext ())
6161 return false ;
6262
63- // General check on access-level of the decl.
6463 auto *DC = where.getDeclContext ();
64+ auto &Context = DC->getASTContext ();
65+
66+ ImportAccessLevel problematicImport = D->getImportAccessFrom (DC);
67+ if (problematicImport.has_value ()) {
68+ auto SF = DC->getParentSourceFile ();
69+ if (SF)
70+ SF->registerAccessLevelUsingImport (problematicImport.value (),
71+ AccessLevel::Public);
72+
73+ if (Context.LangOpts .EnableModuleApiImportRemarks ) {
74+ ModuleDecl *importedVia = problematicImport->module .importedModule ,
75+ *sourceModule = D->getModuleContext ();
76+ Context.Diags .diagnose (loc, diag::module_api_import,
77+ D, importedVia, sourceModule,
78+ importedVia == sourceModule,
79+ /* isImplicit*/ false );
80+ }
81+ }
82+
83+ // General check on access-level of the decl.
6584 auto declAccessScope =
6685 D->getFormalAccessScope (/* useDC=*/ DC,
6786 /* allowUsableFromInline=*/ true );
@@ -72,8 +91,6 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
7291 if (declAccessScope.isPublic ())
7392 return false ;
7493
75- auto &Context = DC->getASTContext ();
76-
7794 // Dynamic declarations were mistakenly not checked in Swift 4.2.
7895 // Do enforce the restriction even in pre-Swift-5 modes if the module we're
7996 // building is resilient, though.
@@ -112,10 +129,9 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
112129
113130 Context.Diags .diagnose (D, diag::resilience_decl_declared_here, D);
114131
115- ImportAccessLevel problematicImport = D->getImportAccessFrom (DC);
116132 if (problematicImport.has_value () &&
117133 problematicImport->accessLevel < D->getFormalAccess ()) {
118- Context.Diags .diagnose (problematicImport->accessLevelLoc ,
134+ Context.Diags .diagnose (problematicImport->importLoc ,
119135 diag::decl_import_via_here, D,
120136 problematicImport->accessLevel ,
121137 problematicImport->module .importedModule );
@@ -133,15 +149,32 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
133149 if (!D)
134150 return false ;
135151
152+ auto exportingModule = where.getDeclContext ()->getParentModule ();
153+ ASTContext &ctx = exportingModule->getASTContext ();
154+
155+ ImportAccessLevel problematicImport = D->getImportAccessFrom (
156+ where.getDeclContext ());
157+ if (problematicImport.has_value ()) {
158+ auto SF = where.getDeclContext ()->getParentSourceFile ();
159+ if (SF)
160+ SF->registerAccessLevelUsingImport (problematicImport.value (),
161+ AccessLevel::Public);
162+
163+ if (ctx.LangOpts .EnableModuleApiImportRemarks ) {
164+ ModuleDecl *importedVia = problematicImport->module .importedModule ,
165+ *sourceModule = D->getModuleContext ();
166+ ctx.Diags .diagnose (loc, diag::module_api_import_aliases,
167+ D, importedVia, sourceModule,
168+ importedVia == sourceModule);
169+ }
170+ }
171+
136172 auto ignoredDowngradeToWarning = DowngradeToWarning::No;
137173 auto originKind =
138174 getDisallowedOriginKind (D, where, ignoredDowngradeToWarning);
139175 if (originKind == DisallowedOriginKind::None)
140176 return false ;
141177
142- auto exportingModule = where.getDeclContext ()->getParentModule ();
143- ASTContext &ctx = exportingModule->getASTContext ();
144-
145178 // As an exception, if the import of the module that defines the desugared
146179 // decl is just missing (as opposed to imported explicitly with reduced
147180 // visibility) then we should only diagnose if we're building a resilient
@@ -184,7 +217,7 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
184217 assert (limitImport.has_value () &&
185218 limitImport->accessLevel < AccessLevel::Public &&
186219 " The import should still be non-public" );
187- ctx.Diags .diagnose (limitImport->accessLevelLoc ,
220+ ctx.Diags .diagnose (limitImport->importLoc ,
188221 diag::decl_import_via_here, D,
189222 limitImport->accessLevel ,
190223 limitImport->module .importedModule );
@@ -288,13 +321,30 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
288321 if (ext->getParentModule ()->isBuiltinModule ())
289322 return false ;
290323
324+ ModuleDecl *M = ext->getParentModule ();
325+ ASTContext &ctx = M->getASTContext ();
326+
327+ ImportAccessLevel problematicImport = ext->getImportAccessFrom (where.getDeclContext ());
328+ if (problematicImport.has_value ()) {
329+ auto SF = where.getDeclContext ()->getParentSourceFile ();
330+ if (SF)
331+ SF->registerAccessLevelUsingImport (problematicImport.value (),
332+ AccessLevel::Public);
333+
334+ if (ctx.LangOpts .EnableModuleApiImportRemarks ) {
335+ ModuleDecl *importedVia = problematicImport->module .importedModule ,
336+ *sourceModule = ext->getModuleContext ();
337+ ctx.Diags .diagnose (loc, diag::module_api_import_conformance,
338+ rootConf->getType (), rootConf->getProtocol (),
339+ importedVia, sourceModule,
340+ importedVia == sourceModule);
341+ }
342+ }
343+
291344 auto originKind = getDisallowedOriginKind (ext, where);
292345 if (originKind == DisallowedOriginKind::None)
293346 return false ;
294347
295- ModuleDecl *M = ext->getParentModule ();
296- ASTContext &ctx = M->getASTContext ();
297-
298348 auto reason = where.getExportabilityReason ();
299349 if (!reason.has_value ())
300350 reason = ExportabilityReason::General;
@@ -323,7 +373,7 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
323373 assert (limitImport.has_value () &&
324374 limitImport->accessLevel < AccessLevel::Public &&
325375 " The import should still be non-public" );
326- ctx.Diags .diagnose (limitImport->accessLevelLoc ,
376+ ctx.Diags .diagnose (limitImport->importLoc ,
327377 diag::decl_import_via_here, ext,
328378 limitImport->accessLevel ,
329379 limitImport->module .importedModule );
0 commit comments