Skip to content

Commit cec9c2f

Browse files
committed
Fix unsupported conditional attributes in Swift 5.7
refs #794
1 parent 35912b3 commit cec9c2f

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

Sources/ArgumentParser/Parsable Properties/CompletionKind.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ public struct CompletionKind {
4343
case custom(@Sendable ([String], Int, String) -> [String])
4444
#if !canImport(Dispatch)
4545
@available(*, unavailable, message: "DispatchSemaphore is unavailable")
46-
#endif
4746
case customAsync(@Sendable ([String], Int, String) async -> [String])
47+
#else
48+
case customAsync(@Sendable ([String], Int, String) async -> [String])
49+
#endif
4850
case customDeprecated(@Sendable ([String]) -> [String])
4951
}
5052

@@ -186,17 +188,20 @@ public struct CompletionKind {
186188
/// except that the closure is asynchronous.
187189
#if !canImport(Dispatch)
188190
@available(*, unavailable, message: "DispatchSemaphore is unavailable")
189-
#endif
190191
@available(macOS 10.15, macCatalyst 13, iOS 13, tvOS 13, watchOS 6, *)
191192
public static func custom(
192193
_ completion: @Sendable @escaping ([String], Int, String) async -> [String]
193194
) -> CompletionKind {
194-
#if !canImport(Dispatch)
195195
fatalError("DispatchSemaphore is unavailable")
196-
#else
196+
}
197+
#else
198+
@available(macOS 10.15, macCatalyst 13, iOS 13, tvOS 13, watchOS 6, *)
199+
public static func custom(
200+
_ completion: @Sendable @escaping ([String], Int, String) async -> [String]
201+
) -> CompletionKind {
197202
CompletionKind(kind: .customAsync(completion))
198-
#endif
199203
}
204+
#endif
200205

201206
/// Deprecated; only kept for backwards compatibility.
202207
///

Sources/ArgumentParser/Parsing/CommandParser.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,15 +531,19 @@ private func parseCustomCompletionArguments(
531531

532532
#if !canImport(Dispatch)
533533
@available(*, unavailable, message: "DispatchSemaphore is unavailable")
534-
#endif
535534
@available(macOS 10.15, macCatalyst 13, iOS 13, tvOS 13, watchOS 6, *)
536535
private func asyncCustomCompletions(
537536
from args: [String],
538537
complete: @escaping @Sendable ([String], Int, String) async -> [String]
539538
) throws -> [String] {
540-
#if !canImport(Dispatch)
541539
throw ParserError.invalidState
542-
#else
540+
}
541+
#else
542+
@available(macOS 10.15, macCatalyst 13, iOS 13, tvOS 13, watchOS 6, *)
543+
private func asyncCustomCompletions(
544+
from args: [String],
545+
complete: @escaping @Sendable ([String], Int, String) async -> [String]
546+
) throws -> [String] {
543547
let (args, completingArgumentIndex, completingPrefix) =
544548
try parseCustomCompletionArguments(from: args)
545549

@@ -557,8 +561,8 @@ private func asyncCustomCompletions(
557561

558562
semaphore.wait()
559563
return completionsBox.withLock { $0 }
560-
#endif
561564
}
565+
#endif
562566

563567
// MARK: Building Command Stacks
564568

0 commit comments

Comments
 (0)