Skip to content

Commit 9f45a4d

Browse files
authored
Merge pull request #71559 from xymus/ambiguous-generated
Sema: ignore inconsistent imports from a file generated by Xcode
2 parents 8cc2a3b + 6c55bb6 commit 9f45a4d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/Sema/ImportResolution.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,8 +1055,15 @@ CheckInconsistentAccessLevelOnImport::evaluate(
10551055
auto mod = SF->getParentModule();
10561056
auto diagnose = [mod](const ImportDecl *implicitImport,
10571057
const ImportDecl *otherImport) {
1058-
auto otherAccessLevel = otherImport->getAccessLevel();
1058+
// Ignore files generated by Xcode. We should probably identify them via
1059+
// an attribuite or frontend flag, until them match the file by name.
1060+
SourceFile *implicitSF =
1061+
implicitImport->getDeclContext()->getParentSourceFile();
1062+
StringRef basename = llvm::sys::path::filename(implicitSF->getFilename());
1063+
if (basename == "GeneratedAssetSymbols.swift")
1064+
return;
10591065

1066+
auto otherAccessLevel = otherImport->getAccessLevel();
10601067
auto &diags = mod->getDiags();
10611068
{
10621069
InFlightDiagnostic error =

test/Sema/access-level-import-inconsistencies.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,16 @@ package import Lib // expected-note {{imported 'package' here}} @:1
6969
import Lib
7070
//--- ManyFiles_AmbiguitySwift6_FileB.swift
7171
internal import Lib
72+
73+
/// Don't report inconsistencies from a file generated by Xcode.
74+
// RUN: %target-swift-frontend -typecheck -I %t \
75+
// RUN -primary-file %t/GeneratedAssetSymbols.swift \
76+
// RUN: %t/UserWrittenFile.swift -verify
77+
// RUN: %target-swift-frontend -typecheck -I %t \
78+
// RUN %t/GeneratedAssetSymbols.swift \
79+
// RUN: -primary-file %t/UserWrittenFile.swift -verify
80+
//--- UserWrittenFile.swift
81+
internal import Lib
82+
//--- GeneratedAssetSymbols.swift
83+
import Lib
84+

0 commit comments

Comments
 (0)