@@ -61,28 +61,15 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
61
61
return false ;
62
62
63
63
// General check on access-level of the decl.
64
+ auto *DC = where.getDeclContext ();
64
65
auto declAccessScope =
65
- D->getFormalAccessScope (/* useDC=*/ nullptr ,
66
+ D->getFormalAccessScope (/* useDC=*/ DC ,
66
67
/* allowUsableFromInline=*/ true );
67
68
68
- // If the decl is imported, check if the import lowers it's access level.
69
- auto importAccessLevel = AccessLevel::Public;
70
- ImportAccessLevel problematicImport = llvm::None;
71
-
72
- auto *DC = where.getDeclContext ();
73
- auto targetModule = D->getDeclContext ()->getParentModule ();
74
- auto file = where.getDeclContext ()->getParentSourceFile ();
75
- if (targetModule != DC->getParentModule () && file) {
76
- problematicImport = file->getImportAccessLevel (targetModule);
77
- if (problematicImport.has_value ())
78
- importAccessLevel = problematicImport->accessLevel ;
79
- }
80
-
81
69
// Public declarations are OK, even if they're SPI or came from an
82
70
// implementation-only import. We'll diagnose exportability violations
83
71
// from diagnoseDeclRefExportability().
84
- if (declAccessScope.isPublic () &&
85
- importAccessLevel == AccessLevel::Public)
72
+ if (declAccessScope.isPublic ())
86
73
return false ;
87
74
88
75
auto &Context = DC->getASTContext ();
@@ -119,20 +106,19 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
119
106
if (downgradeToWarning == DowngradeToWarning::Yes)
120
107
diagID = diag::resilience_decl_unavailable_warn;
121
108
122
- auto diagAccessLevel = std::min (declAccessScope.accessLevelForDiagnostics (),
123
- importAccessLevel);
124
-
109
+ AccessLevel diagAccessLevel = declAccessScope.accessLevelForDiagnostics ();
125
110
Context.Diags .diagnose (loc, diagID, D, diagAccessLevel,
126
111
fragileKind.getSelector ());
127
112
128
113
Context.Diags .diagnose (D, diag::resilience_decl_declared_here, D);
129
114
115
+ ImportAccessLevel problematicImport = D->getImportAccessFrom (DC);
130
116
if (problematicImport.has_value () &&
131
- diagAccessLevel == importAccessLevel ) {
117
+ diagAccessLevel == problematicImport-> accessLevel ) {
132
118
Context.Diags .diagnose (problematicImport->accessLevelLoc ,
133
119
diag::decl_import_via_here, D,
134
120
problematicImport->accessLevel ,
135
- problematicImport->module .importedModule -> getName () );
121
+ problematicImport->module .importedModule );
136
122
}
137
123
138
124
return (downgradeToWarning == DowngradeToWarning::No);
0 commit comments