Merge pull request #78005 from xymus/access-level-import-reexports

Sema: Prioritize @_exported imports over local non-public imports
This commit is contained in:
Alexis Laferrière
2024-12-09 13:35:44 -08:00
committed by GitHub
3 changed files with 83 additions and 3 deletions

View File

@@ -2957,6 +2957,16 @@ SourceFile::getImportAccessLevel(const ModuleDecl *targetModule) const {
restrictiveImport = import;
}
}
// Reexports from the local module take precedence over non-public imports
// and lift all access-level restrictions. We still prioritize file local
// public imports as diagnostics will have an import to point to and
// they are recommended over indirect imports.
if ((!restrictiveImport.has_value() ||
restrictiveImport->accessLevel < AccessLevel::Public) &&
imports.isImportedBy(targetModule, getParentModule()))
return std::nullopt;
return restrictiveImport;
}