Skip to content

Commit fa994e7

Browse files
authored
Merge pull request #61084 from xymus/pub-priv-import-in-swiftinterface
[Sema] Don't error on public imports of private modules in a swiftinterface
2 parents 1640db8 + 1a6a8a7 commit fa994e7

File tree

3 files changed

+47
-28
lines changed

3 files changed

+47
-28
lines changed

include/swift/AST/DiagnosticsSema.def

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

30163016
ERROR(error_public_import_of_private_module,none,
3017-
"private module %0 is imported publicly from the public module %1",
3018-
(Identifier, Identifier))
3017+
"private module %0 is imported publicly from the public module %1",
3018+
(Identifier, Identifier))
30193019

30203020
ERROR(implementation_only_decl_non_override,none,
30213021
"'@_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
@@ -1900,8 +1900,10 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
19001900
#endif
19011901

19021902
bool isImportOfUnderlying = importer->getName() == target->getName();
1903+
auto *SF = ID->getDeclContext()->getParentSourceFile();
19031904
bool treatAsError = enableTreatAsError &&
1904-
!isImportOfUnderlying;
1905+
!isImportOfUnderlying &&
1906+
SF->Kind != SourceFileKind::Interface;
19051907
if (!treatAsError)
19061908
inFlight.limitBehavior(DiagnosticBehavior::Warning);
19071909
}
Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
23
// REQUIRES: VENDOR=apple
34
// REQUIRES: asserts
45

@@ -12,28 +13,28 @@
1213
// RUN: -o %t/sdk/System/Library/PrivateFrameworks/PrivateSwift.framework/Modules/PrivateSwift.swiftmodule/%target-swiftmodule-name
1314

1415
/// Expect errors when building a public client.
15-
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk -module-cache-path %t %s \
16-
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ \
17-
// RUN: -library-level api -verify -D PUBLIC_IMPORTS -module-name MainLib
16+
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk %t/PublicImports.swift \
17+
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ -module-cache-path %t \
18+
// RUN: -library-level api -verify -module-name MainLib
1819

1920
/// Expect no errors when building an SPI client.
20-
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk -module-cache-path %t %s \
21-
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ \
22-
// RUN: -library-level spi -D PUBLIC_IMPORTS -module-name MainLib
21+
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk %t/PublicImports.swift \
22+
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ -module-cache-path %t \
23+
// RUN: -library-level spi -module-name MainLib
2324

2425
/// The driver should also accept the flag and pass it along.
25-
// RUN: %target-swiftc_driver -typecheck -sdk %t/sdk -module-cache-path %t %s \
26-
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ \
27-
// RUN: -library-level spi -D PUBLIC_IMPORTS -module-name MainLib
26+
// RUN: %target-swiftc_driver -typecheck -sdk %t/sdk %t/PublicImports.swift \
27+
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ -module-cache-path %t \
28+
// RUN: -library-level spi -module-name MainLib
2829

2930
/// Expect no errors when building a client with some other library level.
30-
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk -module-cache-path %t %s \
31-
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ \
32-
// RUN: -D PUBLIC_IMPORTS -module-name MainLib
33-
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk -module-cache-path %t %s \
34-
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ \
35-
// RUN: -library-level other -D PUBLIC_IMPORTS -module-name MainLib
36-
#if PUBLIC_IMPORTS
31+
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk %t/PublicImports.swift \
32+
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ -module-cache-path %t \
33+
// RUN: -module-name MainLib
34+
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk %t/PublicImports.swift \
35+
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ -module-cache-path %t \
36+
// RUN: -library-level other -module-name MainLib
37+
//--- PublicImports.swift
3738
import PublicSwift
3839
import PrivateSwift // expected-error{{private module 'PrivateSwift' is imported publicly from the public module 'MainLib'}}
3940

@@ -44,31 +45,47 @@ import LocalClang // expected-error{{private module 'LocalClang' is imported pub
4445
@_exported import MainLib // expected-warning{{private module 'MainLib' is imported publicly from the public module 'MainLib'}}
4546

4647
/// Expect no errors with implementation-only imports.
47-
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk -module-cache-path %t %s \
48-
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ \
48+
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk %t/ImplOnlyImports.swift \
49+
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ -module-cache-path %t \
4950
// RUN: -library-level api -D IMPL_ONLY_IMPORTS
50-
#elseif IMPL_ONLY_IMPORTS
51+
//--- ImplOnlyImports.swift
5152

5253
@_implementationOnly import PrivateSwift
5354
@_implementationOnly import PublicClang_Private
5455
@_implementationOnly import FullyPrivateClang
5556
@_implementationOnly import LocalClang
5657

5758
/// Expect no errors with spi-only imports.
58-
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk -module-cache-path %t %s \
59-
// RUN: -experimental-spi-only-imports \
59+
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk %t/SpiOnlyImports.swift \
60+
// RUN: -experimental-spi-only-imports -module-cache-path %t \
6061
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ \
61-
// RUN: -library-level api -D SPI_ONLY_IMPORTS
62-
#elseif SPI_ONLY_IMPORTS
62+
// RUN: -library-level api
63+
//--- SPIOnlyImports.swift
6364

6465
@_spiOnly import PrivateSwift
6566
@_spiOnly import PublicClang_Private
6667
@_spiOnly import FullyPrivateClang
6768
@_spiOnly import LocalClang
6869

69-
#endif
70-
7170
/// Test error message on an unknown library level name.
7271
// RUN: not %target-swift-frontend -typecheck %s -library-level ThatsNotALibraryLevel 2>&1 \
7372
// RUN: | %FileCheck %s --check-prefix CHECK-ARG
7473
// 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)