From 689a6789fd4e573a9ae43da8eb362cb8db83974c Mon Sep 17 00:00:00 2001 From: Allan Shortlidge Date: Mon, 8 Sep 2025 09:38:28 -0700 Subject: [PATCH 1/2] 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. --- Package@swift-5.8.swift | 14 ++++++++++++++ .../Completions/CompletionsGenerator.swift | 2 ++ .../Completions/FishCompletionsGenerator.swift | 2 ++ .../Completions/ZshCompletionsGenerator.swift | 2 ++ .../Parsable Types/ParsableArguments.swift | 6 ++++++ .../ArgumentParserTestHelpers/StringHelpers.swift | 6 ++++++ .../RepeatExampleTests.swift | 1 + .../RollDiceExampleTests.swift | 1 + 8 files changed, 34 insertions(+) diff --git a/Package@swift-5.8.swift b/Package@swift-5.8.swift index 4306ab956..fb860aff1 100644 --- a/Package@swift-5.8.swift +++ b/Package@swift-5.8.swift @@ -138,3 +138,17 @@ package.targets.append(contentsOf: [ path: "Tools/changelog-authors"), ]) #endif + +for target in package.targets { + switch target.type { + case .regular, .test, .executable: + var settings = target.swiftSettings ?? [] + // https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md + settings.append(.enableUpcomingFeature("MemberImportVisibility")) + target.swiftSettings = settings + case .macro, .plugin, .system, .binary: + break // not applicable + @unknown default: + break // we don't know what to do here, do nothing + } +} diff --git a/Sources/ArgumentParser/Completions/CompletionsGenerator.swift b/Sources/ArgumentParser/Completions/CompletionsGenerator.swift index d196d00be..e5a0a78cc 100644 --- a/Sources/ArgumentParser/Completions/CompletionsGenerator.swift +++ b/Sources/ArgumentParser/Completions/CompletionsGenerator.swift @@ -11,8 +11,10 @@ #if swift(>=6.0) internal import ArgumentParserToolInfo +internal import Foundation #else import ArgumentParserToolInfo +import Foundation #endif /// A shell for which the parser can generate a completion script. diff --git a/Sources/ArgumentParser/Completions/FishCompletionsGenerator.swift b/Sources/ArgumentParser/Completions/FishCompletionsGenerator.swift index 3a722a8e6..072a816f8 100644 --- a/Sources/ArgumentParser/Completions/FishCompletionsGenerator.swift +++ b/Sources/ArgumentParser/Completions/FishCompletionsGenerator.swift @@ -11,8 +11,10 @@ #if swift(>=6.0) internal import ArgumentParserToolInfo +internal import Foundation #else import ArgumentParserToolInfo +import Foundation #endif extension ToolInfoV0 { diff --git a/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift b/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift index 60296aa24..b3a9b4e79 100644 --- a/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift +++ b/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift @@ -11,8 +11,10 @@ #if swift(>=6.0) internal import ArgumentParserToolInfo +internal import Foundation #else import ArgumentParserToolInfo +import Foundation #endif extension ToolInfoV0 { diff --git a/Sources/ArgumentParser/Parsable Types/ParsableArguments.swift b/Sources/ArgumentParser/Parsable Types/ParsableArguments.swift index 1154d6278..671dcdfe9 100644 --- a/Sources/ArgumentParser/Parsable Types/ParsableArguments.swift +++ b/Sources/ArgumentParser/Parsable Types/ParsableArguments.swift @@ -9,6 +9,12 @@ // //===----------------------------------------------------------------------===// +#if swift(>=6.0) +internal import Foundation +#else +import Foundation +#endif + /// A type that can be parsed from a program's command-line arguments. /// /// When you implement a `ParsableArguments` type, all properties must be declared with diff --git a/Sources/ArgumentParserTestHelpers/StringHelpers.swift b/Sources/ArgumentParserTestHelpers/StringHelpers.swift index 5baf377b0..c5fa2e345 100644 --- a/Sources/ArgumentParserTestHelpers/StringHelpers.swift +++ b/Sources/ArgumentParserTestHelpers/StringHelpers.swift @@ -9,6 +9,12 @@ // //===----------------------------------------------------------------------===// +#if swift(>=6.0) +internal import Foundation +#else +import Foundation +#endif + extension Substring { func trimmed() -> Substring { guard let i = lastIndex(where: { $0 != " " }) else { diff --git a/Tests/ArgumentParserExampleTests/RepeatExampleTests.swift b/Tests/ArgumentParserExampleTests/RepeatExampleTests.swift index b0ff5ece8..4410289eb 100644 --- a/Tests/ArgumentParserExampleTests/RepeatExampleTests.swift +++ b/Tests/ArgumentParserExampleTests/RepeatExampleTests.swift @@ -9,6 +9,7 @@ // //===----------------------------------------------------------------------===// +import ArgumentParser import ArgumentParserTestHelpers import XCTest diff --git a/Tests/ArgumentParserExampleTests/RollDiceExampleTests.swift b/Tests/ArgumentParserExampleTests/RollDiceExampleTests.swift index 2d508f2bc..e8abeaf21 100644 --- a/Tests/ArgumentParserExampleTests/RollDiceExampleTests.swift +++ b/Tests/ArgumentParserExampleTests/RollDiceExampleTests.swift @@ -9,6 +9,7 @@ // //===----------------------------------------------------------------------===// +import ArgumentParser import ArgumentParserTestHelpers import XCTest From 33ae082d7460d32c4de7c83129b58aeb2009f3b6 Mon Sep 17 00:00:00 2001 From: Allan Shortlidge Date: Mon, 8 Sep 2025 10:06:45 -0700 Subject: [PATCH 2/2] Replace `#if swift(>=6.0)` guards with `#if compiler(>=6.0)`. All uses of `internal import` were previously garuded 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. --- .../Completions/BashCompletionsGenerator.swift | 2 +- .../ArgumentParser/Completions/CompletionsGenerator.swift | 2 +- .../Completions/FishCompletionsGenerator.swift | 2 +- .../Completions/ZshCompletionsGenerator.swift | 2 +- .../ArgumentParser/Parsable Types/ParsableArguments.swift | 2 +- Sources/ArgumentParser/Parsing/CommandParser.swift | 2 +- Sources/ArgumentParser/Usage/DumpHelpGenerator.swift | 2 +- Sources/ArgumentParser/Usage/MessageInfo.swift | 2 +- Sources/ArgumentParser/Usage/UsageGenerator.swift | 2 +- Sources/ArgumentParser/Utilities/Mutex.swift | 2 +- Sources/ArgumentParserTestHelpers/StringHelpers.swift | 2 +- Tests/ArgumentParserExampleTests/MathExampleTests.swift | 7 +------ 12 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift b/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift index 4f7bd8425..85da31704 100644 --- a/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift +++ b/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if swift(>=6.0) +#if compiler(>=6.0) internal import ArgumentParserToolInfo #else import ArgumentParserToolInfo diff --git a/Sources/ArgumentParser/Completions/CompletionsGenerator.swift b/Sources/ArgumentParser/Completions/CompletionsGenerator.swift index e5a0a78cc..87e3932a0 100644 --- a/Sources/ArgumentParser/Completions/CompletionsGenerator.swift +++ b/Sources/ArgumentParser/Completions/CompletionsGenerator.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if swift(>=6.0) +#if compiler(>=6.0) internal import ArgumentParserToolInfo internal import Foundation #else diff --git a/Sources/ArgumentParser/Completions/FishCompletionsGenerator.swift b/Sources/ArgumentParser/Completions/FishCompletionsGenerator.swift index 072a816f8..549fdf846 100644 --- a/Sources/ArgumentParser/Completions/FishCompletionsGenerator.swift +++ b/Sources/ArgumentParser/Completions/FishCompletionsGenerator.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if swift(>=6.0) +#if compiler(>=6.0) internal import ArgumentParserToolInfo internal import Foundation #else diff --git a/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift b/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift index b3a9b4e79..4ed8c90cf 100644 --- a/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift +++ b/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if swift(>=6.0) +#if compiler(>=6.0) internal import ArgumentParserToolInfo internal import Foundation #else diff --git a/Sources/ArgumentParser/Parsable Types/ParsableArguments.swift b/Sources/ArgumentParser/Parsable Types/ParsableArguments.swift index 671dcdfe9..6eb0d5483 100644 --- a/Sources/ArgumentParser/Parsable Types/ParsableArguments.swift +++ b/Sources/ArgumentParser/Parsable Types/ParsableArguments.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if swift(>=6.0) +#if compiler(>=6.0) internal import Foundation #else import Foundation diff --git a/Sources/ArgumentParser/Parsing/CommandParser.swift b/Sources/ArgumentParser/Parsing/CommandParser.swift index 3f2f08ccd..e4b42f440 100644 --- a/Sources/ArgumentParser/Parsing/CommandParser.swift +++ b/Sources/ArgumentParser/Parsing/CommandParser.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if swift(>=6.0) +#if compiler(>=6.0) #if canImport(Dispatch) @preconcurrency private import class Dispatch.DispatchSemaphore #endif diff --git a/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift b/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift index 1dbd28fdf..895b27a6d 100644 --- a/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift +++ b/Sources/ArgumentParser/Usage/DumpHelpGenerator.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if swift(>=6.0) +#if compiler(>=6.0) internal import ArgumentParserToolInfo internal import class Foundation.JSONEncoder #else diff --git a/Sources/ArgumentParser/Usage/MessageInfo.swift b/Sources/ArgumentParser/Usage/MessageInfo.swift index 4e42b4601..7d0c8a2c3 100644 --- a/Sources/ArgumentParser/Usage/MessageInfo.swift +++ b/Sources/ArgumentParser/Usage/MessageInfo.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if swift(>=6.0) +#if compiler(>=6.0) internal import protocol Foundation.LocalizedError internal import class Foundation.NSError #else diff --git a/Sources/ArgumentParser/Usage/UsageGenerator.swift b/Sources/ArgumentParser/Usage/UsageGenerator.swift index 9c628c0cc..f73d80d1f 100644 --- a/Sources/ArgumentParser/Usage/UsageGenerator.swift +++ b/Sources/ArgumentParser/Usage/UsageGenerator.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if swift(>=6.0) +#if compiler(>=6.0) internal import protocol Foundation.LocalizedError #else import protocol Foundation.LocalizedError diff --git a/Sources/ArgumentParser/Utilities/Mutex.swift b/Sources/ArgumentParser/Utilities/Mutex.swift index 2f3bd040d..3a3c4244b 100644 --- a/Sources/ArgumentParser/Utilities/Mutex.swift +++ b/Sources/ArgumentParser/Utilities/Mutex.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if swift(>=6.0) +#if compiler(>=6.0) internal import Foundation #else import Foundation diff --git a/Sources/ArgumentParserTestHelpers/StringHelpers.swift b/Sources/ArgumentParserTestHelpers/StringHelpers.swift index c5fa2e345..639ed4479 100644 --- a/Sources/ArgumentParserTestHelpers/StringHelpers.swift +++ b/Sources/ArgumentParserTestHelpers/StringHelpers.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -#if swift(>=6.0) +#if compiler(>=6.0) internal import Foundation #else import Foundation diff --git a/Tests/ArgumentParserExampleTests/MathExampleTests.swift b/Tests/ArgumentParserExampleTests/MathExampleTests.swift index f1928f915..2c9a666cb 100644 --- a/Tests/ArgumentParserExampleTests/MathExampleTests.swift +++ b/Tests/ArgumentParserExampleTests/MathExampleTests.swift @@ -9,15 +9,10 @@ // //===----------------------------------------------------------------------===// -import ArgumentParser import ArgumentParserTestHelpers import XCTest -#if swift(>=6.0) -@testable internal import struct ArgumentParser.CompletionShell -#else -@testable import struct ArgumentParser.CompletionShell -#endif +@testable import ArgumentParser final class MathExampleTests: XCTestCase { override func setUp() {