From 076e9dcbe08295ee5dbbff9b3135a167008c01ad Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Tue, 1 Jul 2025 11:13:39 -0400 Subject: [PATCH] Designate `_SendableMetatype` as a marker protocol --- .../Utilities/SwiftExtensions.swift | 4 +-- .../PositionalEndToEndTests.swift | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Sources/ArgumentParser/Utilities/SwiftExtensions.swift b/Sources/ArgumentParser/Utilities/SwiftExtensions.swift index b09403bf..f32a9ddd 100644 --- a/Sources/ArgumentParser/Utilities/SwiftExtensions.swift +++ b/Sources/ArgumentParser/Utilities/SwiftExtensions.swift @@ -11,7 +11,7 @@ #if compiler(>=6.2) /// Designates a type as having a sendable metatype. -public protocol _SendableMetatype: SendableMetatype {} +@_marker public protocol _SendableMetatype: SendableMetatype {} #else -public protocol _SendableMetatype {} +@_marker public protocol _SendableMetatype {} #endif diff --git a/Tests/ArgumentParserEndToEndTests/PositionalEndToEndTests.swift b/Tests/ArgumentParserEndToEndTests/PositionalEndToEndTests.swift index 8ea5c578..7d15530a 100644 --- a/Tests/ArgumentParserEndToEndTests/PositionalEndToEndTests.swift +++ b/Tests/ArgumentParserEndToEndTests/PositionalEndToEndTests.swift @@ -241,3 +241,33 @@ extension PositionalEndToEndTests { } } } + +// MARK: Conditional ExpressibleByArgument conformance + +// Note: This retroactive conformance is a compilation test +extension Range: ArgumentParser.ExpressibleByArgument { + public init?(argument: String) { + guard let i = argument.firstIndex(of: ":"), + let low = Int(String(argument[.. + } + + func testParseCustomRangeConformance() throws { + AssertParse(HasRange.self, ["0:4"]) { args in + XCTAssertEqual(args.range, 0..<4) + } + + XCTAssertThrowsError(try HasRange.parse([])) + XCTAssertThrowsError(try HasRange.parse(["1"])) + XCTAssertThrowsError(try HasRange.parse(["1:0"])) + } +}