Skip to content

Commit 4f680a7

Browse files
authored
Adopt upcoming Swift language feature MemberImportVisibility (#803)
* Adopt upcoming Swift language feature MemberImportVisibility. Enable the language feature flag for SE-0444. This instructs the compiler to be stricter about requiring import declarations in order to access member declarations. * Replace `#if swift(>=6.0)` guards with `#if compiler(>=6.0)`. All uses of `internal import` were previously guarded with `#if swift(>=6.0)`, presumably to handle differences in compiler support for `internal import`. However, `#if swift(>=)` is not the correct directive to use for this purpose, as it primarily tests the language mode that is enabled. These existing conditionals never evaluated true when building this package since it is not configured to build with Swift 6 enabled. Instead, use `#if compiler(>=6.0)` which correctly predicates the imports on only the compiler version.
1 parent 91662e3 commit 4f680a7

15 files changed

+44
-15
lines changed

Package@swift-5.8.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,17 @@ package.targets.append(contentsOf: [
138138
path: "Tools/changelog-authors"),
139139
])
140140
#endif
141+
142+
for target in package.targets {
143+
switch target.type {
144+
case .regular, .test, .executable:
145+
var settings = target.swiftSettings ?? []
146+
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md
147+
settings.append(.enableUpcomingFeature("MemberImportVisibility"))
148+
target.swiftSettings = settings
149+
case .macro, .plugin, .system, .binary:
150+
break // not applicable
151+
@unknown default:
152+
break // we don't know what to do here, do nothing
153+
}
154+
}

Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
#if swift(>=6.0)
12+
#if compiler(>=6.0)
1313
internal import ArgumentParserToolInfo
1414
#else
1515
import ArgumentParserToolInfo

Sources/ArgumentParser/Completions/CompletionsGenerator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
#if swift(>=6.0)
12+
#if compiler(>=6.0)
1313
internal import ArgumentParserToolInfo
14+
internal import Foundation
1415
#else
1516
import ArgumentParserToolInfo
17+
import Foundation
1618
#endif
1719

1820
/// A shell for which the parser can generate a completion script.

Sources/ArgumentParser/Completions/FishCompletionsGenerator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
#if swift(>=6.0)
12+
#if compiler(>=6.0)
1313
internal import ArgumentParserToolInfo
14+
internal import Foundation
1415
#else
1516
import ArgumentParserToolInfo
17+
import Foundation
1618
#endif
1719

1820
extension ToolInfoV0 {

Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
#if swift(>=6.0)
12+
#if compiler(>=6.0)
1313
internal import ArgumentParserToolInfo
14+
internal import Foundation
1415
#else
1516
import ArgumentParserToolInfo
17+
import Foundation
1618
#endif
1719

1820
extension ToolInfoV0 {

Sources/ArgumentParser/Parsable Types/ParsableArguments.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12+
#if compiler(>=6.0)
13+
internal import Foundation
14+
#else
15+
import Foundation
16+
#endif
17+
1218
/// A type that can be parsed from a program's command-line arguments.
1319
///
1420
/// When you implement a `ParsableArguments` type, all properties must be declared with

Sources/ArgumentParser/Parsing/CommandParser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
#if swift(>=6.0)
12+
#if compiler(>=6.0)
1313
#if canImport(Dispatch)
1414
@preconcurrency private import class Dispatch.DispatchSemaphore
1515
#endif

Sources/ArgumentParser/Usage/DumpHelpGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
#if swift(>=6.0)
12+
#if compiler(>=6.0)
1313
internal import ArgumentParserToolInfo
1414
internal import class Foundation.JSONEncoder
1515
#else

Sources/ArgumentParser/Usage/MessageInfo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
#if swift(>=6.0)
12+
#if compiler(>=6.0)
1313
internal import protocol Foundation.LocalizedError
1414
internal import class Foundation.NSError
1515
#else

Sources/ArgumentParser/Usage/UsageGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
#if swift(>=6.0)
12+
#if compiler(>=6.0)
1313
internal import protocol Foundation.LocalizedError
1414
#else
1515
import protocol Foundation.LocalizedError

0 commit comments

Comments
 (0)