Skip to content

Commit 1a6a8a7

Browse files
committed
[Sema] Don't error on public imports of private modules in a swiftinterface
1 parent 2fd5178 commit 1a6a8a7

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,8 +2993,8 @@ NOTE(spi_only_import_conflict_here,none,
29932993
"imported for SPI only here", ())
29942994

29952995
ERROR(error_public_import_of_private_module,none,
2996-
"private module %0 is imported publicly from the public module %1",
2997-
(Identifier, Identifier))
2996+
"private module %0 is imported publicly from the public module %1",
2997+
(Identifier, Identifier))
29982998

29992999
ERROR(implementation_only_decl_non_override,none,
30003000
"'@_implementationOnly' can only be used on overrides", ())

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1867,8 +1867,10 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
18671867
#endif
18681868

18691869
bool isImportOfUnderlying = importer->getName() == target->getName();
1870+
auto *SF = ID->getDeclContext()->getParentSourceFile();
18701871
bool treatAsError = enableTreatAsError &&
1871-
!isImportOfUnderlying;
1872+
!isImportOfUnderlying &&
1873+
SF->Kind != SourceFileKind::Interface;
18721874
if (!treatAsError)
18731875
inFlight.limitBehavior(DiagnosticBehavior::Warning);
18741876
}

test/Sema/implementation-only-import-suggestion.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,21 @@ import LocalClang // expected-error{{private module 'LocalClang' is imported pub
7171
// RUN: not %target-swift-frontend -typecheck %s -library-level ThatsNotALibraryLevel 2>&1 \
7272
// RUN: | %FileCheck %s --check-prefix CHECK-ARG
7373
// CHECK-ARG: error: unknown library level 'ThatsNotALibraryLevel', expected one of 'api', 'spi' or 'other'
74+
75+
/// Expect no errors in swiftinterfaces.
76+
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.private.swiftinterface) \
77+
// RUN: -sdk %t/sdk -module-cache-path %t -F %t/sdk/System/Library/PrivateFrameworks/ \
78+
// RUN: -I %t -module-name Client
79+
80+
//--- Client.private.swiftinterface
81+
// swift-interface-format-version: 1.0
82+
// swift-compiler-version: Swift version 5.8-dev effective-4.1.50
83+
// swift-module-flags: -swift-version 4 -module-name Client -library-level api
84+
85+
import PublicSwift
86+
import PrivateSwift
87+
import PublicClang
88+
import PublicClang_Private
89+
import FullyPrivateClang
90+
import LocalClang
91+
@_exported import MainLib

0 commit comments

Comments
 (0)