Skip to content

Handle Swift 6.2 sendability changes #789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/ArgumentParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ add_library(ArgumentParser
Utilities/Platform.swift
Utilities/SequenceExtensions.swift
Utilities/StringExtensions.swift
Utilities/SwiftExtensions.swift
Utilities/Tree.swift

Validators/CodingKeyValidator.swift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

/// A type that can be expressed as a command-line argument.
public protocol ExpressibleByArgument {
public protocol ExpressibleByArgument: _SendableMetatype {
/// Creates a new instance of this type from a command-line-specified
/// argument.
init?(argument: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
///
/// When you implement a `ParsableArguments` type, all properties must be declared with
/// one of the four property wrappers provided by the `ArgumentParser` library.
public protocol ParsableArguments: Decodable {
public protocol ParsableArguments: Decodable, _SendableMetatype {
/// Creates an instance of this parsable type using the definitions
/// given by each property's wrapper.
init()
Expand Down
17 changes: 17 additions & 0 deletions Sources/ArgumentParser/Utilities/SwiftExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Argument Parser open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

#if compiler(>=6.2)
/// Designates a type as having a sendable metatype.
public protocol _SendableMetatype: SendableMetatype {}
#else
public protocol _SendableMetatype {}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ extension Array where Element == Name {
// MARK: -

private struct Foo: ParsableCommand {
enum Subgroup: Equatable {
enum Subgroup: Equatable, Sendable {
case first(Int)
case second(Int)

@Sendable
static func makeFirst(_ str: String) throws -> Subgroup {
guard let value = Int(str) else {
throw ValidationError("Not a valid integer for 'first'")
}
return .first(value)
}

@Sendable
static func makeSecond(_ str: String) throws -> Subgroup {
guard let value = Int(str) else {
throw ValidationError("Not a valid integer for 'second'")
Expand Down
2 changes: 2 additions & 0 deletions Tests/ArgumentParserUnitTests/HelpGenerationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ extension HelpGenerationTests {
enum OptionFlags: String, EnumerableFlag { case optional, required }
enum Degree {
case bachelor, graduate, doctorate

@Sendable
static func degreeTransform(_ string: String) throws -> Degree {
switch string {
case "bachelor":
Expand Down
1 change: 1 addition & 0 deletions Tests/ArgumentParserUnitTests/UsageGenerationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ extension UsageGenerationTests {
enum Color {
case red, blue

@Sendable
static func transform(_ string: String) throws -> Color {
switch string {
case "red":
Expand Down
Loading