Skip to content

Commit d770075

Browse files
committed
[Sema] Use new services to check access-level on imports in inlinable code
This cleans up the implementation on the call site.
1 parent 377ecf4 commit d770075

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,15 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
6161
return false;
6262

6363
// General check on access-level of the decl.
64+
auto *DC = where.getDeclContext();
6465
auto declAccessScope =
65-
D->getFormalAccessScope(/*useDC=*/nullptr,
66+
D->getFormalAccessScope(/*useDC=*/DC,
6667
/*allowUsableFromInline=*/true);
6768

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-
8169
// Public declarations are OK, even if they're SPI or came from an
8270
// implementation-only import. We'll diagnose exportability violations
8371
// from diagnoseDeclRefExportability().
84-
if (declAccessScope.isPublic() &&
85-
importAccessLevel == AccessLevel::Public)
72+
if (declAccessScope.isPublic())
8673
return false;
8774

8875
auto &Context = DC->getASTContext();
@@ -119,20 +106,19 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
119106
if (downgradeToWarning == DowngradeToWarning::Yes)
120107
diagID = diag::resilience_decl_unavailable_warn;
121108

122-
auto diagAccessLevel = std::min(declAccessScope.accessLevelForDiagnostics(),
123-
importAccessLevel);
124-
109+
AccessLevel diagAccessLevel = declAccessScope.accessLevelForDiagnostics();
125110
Context.Diags.diagnose(loc, diagID, D, diagAccessLevel,
126111
fragileKind.getSelector());
127112

128113
Context.Diags.diagnose(D, diag::resilience_decl_declared_here, D);
129114

115+
ImportAccessLevel problematicImport = D->getImportAccessFrom(DC);
130116
if (problematicImport.has_value() &&
131-
diagAccessLevel == importAccessLevel) {
117+
diagAccessLevel == problematicImport->accessLevel) {
132118
Context.Diags.diagnose(problematicImport->accessLevelLoc,
133119
diag::decl_import_via_here, D,
134120
problematicImport->accessLevel,
135-
problematicImport->module.importedModule->getName());
121+
problematicImport->module.importedModule);
136122
}
137123

138124
return (downgradeToWarning == DowngradeToWarning::No);

0 commit comments

Comments
 (0)