Skip to content

Commit f157651

Browse files
authored
Designate _SendableMetatype as a marker protocol (#792)
1 parent 852f74c commit f157651

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

Sources/ArgumentParser/Utilities/SwiftExtensions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#if compiler(>=6.2)
1313
/// Designates a type as having a sendable metatype.
14-
public protocol _SendableMetatype: SendableMetatype {}
14+
@_marker public protocol _SendableMetatype: SendableMetatype {}
1515
#else
16-
public protocol _SendableMetatype {}
16+
@_marker public protocol _SendableMetatype {}
1717
#endif

Tests/ArgumentParserEndToEndTests/PositionalEndToEndTests.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,33 @@ extension PositionalEndToEndTests {
241241
}
242242
}
243243
}
244+
245+
// MARK: Conditional ExpressibleByArgument conformance
246+
247+
// Note: This retroactive conformance is a compilation test
248+
extension Range<Int>: ArgumentParser.ExpressibleByArgument {
249+
public init?(argument: String) {
250+
guard let i = argument.firstIndex(of: ":"),
251+
let low = Int(String(argument[..<i])),
252+
let high = Int(String(argument[i...].dropFirst())),
253+
low <= high
254+
else { return nil }
255+
self = low..<high
256+
}
257+
}
258+
259+
extension PositionalEndToEndTests {
260+
struct HasRange: ParsableArguments {
261+
@Argument var range: Range<Int>
262+
}
263+
264+
func testParseCustomRangeConformance() throws {
265+
AssertParse(HasRange.self, ["0:4"]) { args in
266+
XCTAssertEqual(args.range, 0..<4)
267+
}
268+
269+
XCTAssertThrowsError(try HasRange.parse([]))
270+
XCTAssertThrowsError(try HasRange.parse(["1"]))
271+
XCTAssertThrowsError(try HasRange.parse(["1:0"]))
272+
}
273+
}

0 commit comments

Comments
 (0)