@@ -76,20 +76,15 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
76
76
}
77
77
78
78
// Remember that the module defining the decl must be imported publicly.
79
- recordRequiredImportAccessLevelForDecl (D, DC, AccessLevel::Public);
80
-
81
- // Emit a remark explaining the required access level.
82
- ImportAccessLevel problematicImport = D->getImportAccessFrom (DC);
83
- if (problematicImport.has_value ()) {
84
- if (Context.LangOpts .EnableModuleApiImportRemarks ) {
85
- ModuleDecl *importedVia = problematicImport->module .importedModule ,
86
- *sourceModule = D->getModuleContext ();
87
- Context.Diags .diagnose (loc, diag::module_api_import,
88
- D, importedVia, sourceModule,
89
- importedVia == sourceModule,
90
- /* isImplicit*/ false );
91
- }
92
- }
79
+ recordRequiredImportAccessLevelForDecl (
80
+ D, DC, AccessLevel::Public,
81
+ [&](AttributedImport<ImportedModule> attributedImport) {
82
+ ModuleDecl *importedVia = attributedImport.module .importedModule ,
83
+ *sourceModule = D->getModuleContext ();
84
+ Context.Diags .diagnose (loc, diag::module_api_import, D, importedVia,
85
+ sourceModule, importedVia == sourceModule,
86
+ /* isImplicit*/ false );
87
+ });
93
88
94
89
// General check on access-level of the decl.
95
90
auto declAccessScope =
@@ -140,6 +135,7 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
140
135
141
136
Context.Diags .diagnose (D, diag::resilience_decl_declared_here, D);
142
137
138
+ ImportAccessLevel problematicImport = D->getImportAccessFrom (DC);
143
139
if (problematicImport.has_value () &&
144
140
problematicImport->accessLevel < D->getFormalAccess ()) {
145
141
Context.Diags .diagnose (problematicImport->importLoc ,
@@ -166,19 +162,14 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
166
162
167
163
// Remember that the module defining the underlying type must be imported
168
164
// publicly.
169
- recordRequiredImportAccessLevelForDecl (D, DC, AccessLevel::Public);
170
-
171
- // Emit a remark explaining the required access level.
172
- ImportAccessLevel problematicImport = D->getImportAccessFrom (DC);
173
- if (problematicImport.has_value ()) {
174
- if (ctx.LangOpts .EnableModuleApiImportRemarks ) {
175
- ModuleDecl *importedVia = problematicImport->module .importedModule ,
176
- *sourceModule = D->getModuleContext ();
177
- ctx.Diags .diagnose (loc, diag::module_api_import_aliases,
178
- D, importedVia, sourceModule,
179
- importedVia == sourceModule);
180
- }
181
- }
165
+ recordRequiredImportAccessLevelForDecl (
166
+ D, DC, AccessLevel::Public,
167
+ [&](AttributedImport<ImportedModule> attributedImport) {
168
+ ModuleDecl *importedVia = attributedImport.module .importedModule ,
169
+ *sourceModule = D->getModuleContext ();
170
+ ctx.Diags .diagnose (loc, diag::module_api_import_aliases, D, importedVia,
171
+ sourceModule, importedVia == sourceModule);
172
+ });
182
173
183
174
auto ignoredDowngradeToWarning = DowngradeToWarning::No;
184
175
auto originKind =
@@ -249,7 +240,19 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
249
240
auto originKind = getDisallowedOriginKind (D, where, downgradeToWarning);
250
241
251
242
// Remember that the module defining the decl must be imported publicly.
252
- recordRequiredImportAccessLevelForDecl (D, DC, AccessLevel::Public);
243
+ recordRequiredImportAccessLevelForDecl (
244
+ D, DC, AccessLevel::Public,
245
+ [&](AttributedImport<ImportedModule> attributedImport) {
246
+ if (where.isExported () && reason != ExportabilityReason::General &&
247
+ originKind != DisallowedOriginKind::NonPublicImport) {
248
+ // These may be reported twice, for the Type and for the TypeRepr.
249
+ ModuleDecl *importedVia = attributedImport.module .importedModule ,
250
+ *sourceModule = D->getModuleContext ();
251
+ ctx.Diags .diagnose (loc, diag::module_api_import, D, importedVia,
252
+ sourceModule, importedVia == sourceModule,
253
+ /* isImplicit*/ false );
254
+ }
255
+ });
253
256
254
257
// Access levels from imports are reported with the others access levels.
255
258
// Except for extensions and protocol conformances, we report them here.
@@ -269,21 +272,6 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
269
272
return false ;
270
273
}
271
274
272
- // Emit a remark explaining the required access level.
273
- ImportAccessLevel import = D->getImportAccessFrom (DC);
274
- if (ctx.LangOpts .EnableModuleApiImportRemarks &&
275
- import.has_value () && where.isExported () &&
276
- reason != ExportabilityReason::General &&
277
- originKind != DisallowedOriginKind::NonPublicImport) {
278
- // These may be reported twice, for the Type and for the TypeRepr.
279
- ModuleDecl *importedVia = import->module .importedModule ,
280
- *sourceModule = D->getModuleContext ();
281
- ctx.Diags .diagnose (loc, diag::module_api_import,
282
- D, importedVia, sourceModule,
283
- importedVia == sourceModule,
284
- /* isImplicit*/ false );
285
- }
286
-
287
275
if (originKind == DisallowedOriginKind::None)
288
276
return false ;
289
277
@@ -330,6 +318,7 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
330
318
}
331
319
332
320
// If limited by an import, note which one.
321
+ ImportAccessLevel import = D->getImportAccessFrom (DC);
333
322
if (originKind == DisallowedOriginKind::NonPublicImport) {
334
323
assert (import.has_value () &&
335
324
import->accessLevel < AccessLevel::Public &&
@@ -379,20 +368,16 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
379
368
380
369
// Remember that the module defining the conformance must be imported
381
370
// publicly.
382
- recordRequiredImportAccessLevelForDecl (ext, DC, AccessLevel::Public);
383
-
384
- // Emit a remark explaining the required access level.
385
- ImportAccessLevel problematicImport = ext->getImportAccessFrom (DC);
386
- if (problematicImport.has_value ()) {
387
- if (ctx.LangOpts .EnableModuleApiImportRemarks ) {
388
- ModuleDecl *importedVia = problematicImport->module .importedModule ,
389
- *sourceModule = ext->getModuleContext ();
390
- ctx.Diags .diagnose (loc, diag::module_api_import_conformance,
391
- rootConf->getType (), rootConf->getProtocol (),
392
- importedVia, sourceModule,
393
- importedVia == sourceModule);
394
- }
395
- }
371
+ recordRequiredImportAccessLevelForDecl (
372
+ ext, DC, AccessLevel::Public,
373
+ [&](AttributedImport<ImportedModule> attributedImport) {
374
+ ModuleDecl *importedVia = attributedImport.module .importedModule ,
375
+ *sourceModule = ext->getModuleContext ();
376
+ ctx.Diags .diagnose (loc, diag::module_api_import_conformance,
377
+ rootConf->getType (), rootConf->getProtocol (),
378
+ importedVia, sourceModule,
379
+ importedVia == sourceModule);
380
+ });
396
381
397
382
auto originKind = getDisallowedOriginKind (ext, where);
398
383
if (originKind == DisallowedOriginKind::None)
0 commit comments