Skip to content

Commit 6dbfc8c

Browse files
authored
Merge pull request #74035 from xymus/access-level-explicitly-public
Sema: Don't report ambiguities on an explicitly public import
2 parents dbf9d5a + f9fe643 commit 6dbfc8c

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

lib/Sema/ImportResolution.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,13 @@ CheckInconsistentAccessLevelOnImport::evaluate(
10831083
return;
10841084

10851085
auto otherAccessLevel = otherImport->getAccessLevel();
1086+
1087+
// Only report ambiguities with non-public imports as bare imports are
1088+
// public when this diagnostic is active. Do not report ambiguities
1089+
// between implicitly vs explicitly public.
1090+
if (otherAccessLevel == AccessLevel::Public)
1091+
return;
1092+
10861093
auto &diags = mod->getDiags();
10871094
{
10881095
InFlightDiagnostic error =

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/// Don't report any mismatch.
99

1010
// RUN: %empty-directory(%t)
11-
// RUN: split-file %s %t
11+
// RUN: split-file --leading-lines %s %t
1212

1313
/// Build the library.
1414
// RUN: %target-swift-frontend -emit-module %t/Lib.swift -o %t
@@ -68,6 +68,14 @@ import Lib
6868
//--- ManyFiles_AmbiguitySwift6_FileB.swift
6969
internal import Lib
7070

71+
/// Don't report an ambiguity between an explicitly vs implicitly public import.
72+
// RUN: %target-swift-frontend -typecheck %t/ManyFiles_AmbiguityPublicExplicitVsImplicit_File?.swift -I %t \
73+
// RUN: -verify
74+
//--- ManyFiles_AmbiguityPublicExplicitVsImplicit_FileA.swift
75+
import Lib
76+
//--- ManyFiles_AmbiguityPublicExplicitVsImplicit_FileB.swift
77+
public import Lib // expected-warning {{public import of 'Lib' was not used in public declarations or inlinable code}}
78+
7179
/// Don't report inconsistencies from a file generated by Xcode.
7280
// RUN: %target-swift-frontend -typecheck -I %t \
7381
// RUN -primary-file %t/GeneratedAssetSymbols.swift \

test/Sema/access-level-import-inconsistent-same-file.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ internal import Lib1 // expected-warning {{module 'Lib1' is imported as 'public'
6363

6464
// There's no warning about "will be ignored" for a matching implicit access level.
6565
public import Lib2
66-
// expected-note @-1 {{imported 'public' here}}
6766
import Lib2
68-
// expected-error @-1 {{ambiguous implicit access level for import of 'Lib2'; it is imported as 'public' elsewhere}}
69-
// expected-note @-2 {{silence these warnings by adopting the upcoming feature 'InternalImportsByDefault'}}
7067

7168
public func dummyAPI(t: Lib1.Type1, t2: Lib2.Type1) {}
7269

test/Sema/superfluously-public-imports.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,8 @@ public struct Extended {
123123

124124
//--- Client_Swift5.swift
125125
/// No diagnostics should be raised on the implicit access level.
126-
import UnusedImport // expected-error {{ambiguous implicit access level for import of 'UnusedImport'; it is imported as 'public' elsewhere}}
127-
// expected-note @-1 {{silence these warnings by adopting the upcoming feature 'InternalImportsByDefault'}}
126+
import UnusedImport
128127
public import UnusedImport // expected-warning {{public import of 'UnusedImport' was not used in public declarations or inlinable code}} {{1-7=internal}}
129-
// expected-note @-1 {{imported 'public' here}}
130128

131129
//--- Client.swift
132130
public import DepUsedFromInlinableCode

0 commit comments

Comments
 (0)