Merge pull request #64014 from xymus/access-level-import

[Sema] Diagnose exportability of decls limited by a non-public import
This commit is contained in:
Alexis Laferrière
2023-03-02 10:11:15 -08:00
committed by GitHub
11 changed files with 1233 additions and 123 deletions

View File

@@ -2944,6 +2944,29 @@ RestrictedImportKind SourceFile::getRestrictedImportKind(const ModuleDecl *modul
return importKind;
}
ImportAccessLevel
SourceFile::getImportAccessLevel(const ModuleDecl *targetModule) const {
assert(Imports.hasValue());
// Leave it to the caller to avoid calling this service for a self import.
// We want to return AccessLevel::Public, but there's no import site to return.
assert(targetModule != getParentModule() &&
"getImportAccessLevel doesn't support checking for a self-import");
auto &imports = getASTContext().getImportCache();
ImportAccessLevel restrictiveImport = None;
for (auto &import : *Imports) {
if ((!restrictiveImport.has_value() ||
import.accessLevel > restrictiveImport->accessLevel) &&
imports.isImportedBy(targetModule, import.module.importedModule)) {
restrictiveImport = import;
}
}
return restrictiveImport;
}
bool ModuleDecl::isImportedImplementationOnly(const ModuleDecl *module) const {
if (module == this) return false;