Sema: ignore inconsistent bare imports from a file generated by Xcode

In Swift 5 mode, the compiler reports when two files import the same
module, where one file has a bare import and the other an access-level
import. This avoids unintentionally promoting the import to public when
preexisting code marked it otherwise.

Exempt a file generated by Xcode from this check as it's not user
modifiable.

In the future, we should identify such generated files properly. Either
with a new attribute or in the way they are passed to the compiler.

rdar://122032472
This commit is contained in:
Alexis Laferrière
2024-02-12 10:50:54 -08:00
parent 8bb6846285
commit 6c55bb6b4b
2 changed files with 21 additions and 1 deletions

View File

@@ -1055,8 +1055,15 @@ CheckInconsistentAccessLevelOnImport::evaluate(
auto mod = SF->getParentModule();
auto diagnose = [mod](const ImportDecl *implicitImport,
const ImportDecl *otherImport) {
auto otherAccessLevel = otherImport->getAccessLevel();
// Ignore files generated by Xcode. We should probably identify them via
// an attribuite or frontend flag, until them match the file by name.
SourceFile *implicitSF =
implicitImport->getDeclContext()->getParentSourceFile();
StringRef basename = llvm::sys::path::filename(implicitSF->getFilename());
if (basename == "GeneratedAssetSymbols.swift")
return;
auto otherAccessLevel = otherImport->getAccessLevel();
auto &diags = mod->getDiags();
{
InFlightDiagnostic error =