Skip to content

Commit

Permalink
Fix some Swift 5.6 compatibility issues (#516)
Browse files Browse the repository at this point in the history
* Use existential CodingKey parameters consistently

Swift 5.7 supports implicit opening for existentials, so these
conversions from `CodingKey` parameters to pass to methods that
are generic over `CodingKey` work fine. Prior to Swift 5.7, however,
these don't compile, with the message that `CodingKey` doesn't conform
to itself.

* Bump the required Swift version for the count-lines test

The overload resolution for the `static func main()` in an `@main`
type still had issues in Swift 5.6, such that a package with a min.
platform below that which works for concurrency backdeployment doesn't
properly resolve the AsyncParsableCommand `main()` function. In
Swift 5.7, this is properly resolved, so just the availability on
the main type is sufficient.

This change just skips the test of `count-lines` prior to Swift 5.7,
so that we can maintain the open platform minimum for the package
as a whole.
  • Loading branch information
natecook1000 authored Nov 4, 2022
1 parent 4256f88 commit 5535a95
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
.vscode
.*.sw?
*.docc-build
*.vs
16 changes: 0 additions & 16 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,3 @@ var package = Package(
resources: [.copy("CountLinesTest.txt")]),
]
)

#if swift(>=5.6) && os(macOS)
package.targets.append(contentsOf: [
// Examples
.executableTarget(
name: "count-lines",
dependencies: ["ArgumentParser"],
path: "Examples/count-lines"),

// Tools
.executableTarget(
name: "changelog-authors",
dependencies: ["ArgumentParser"],
path: "Tools/changelog-authors"),
])
#endif
4 changes: 2 additions & 2 deletions Sources/ArgumentParser/Parsing/InputKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct InputKey: Hashable {
/// - Parameter codingKey: The base ``CodingKey``
/// - Parameter path: The list of ``CodingKey`` values that lead to this one. May be empty.
@inlinable
init<C: CodingKey>(codingKey: C, path: [CodingKey]) {
init(codingKey: CodingKey, path: [CodingKey]) {
self.init(name: codingKey.stringValue, parent: Parent(InputKey(path: path)))
}

Expand Down Expand Up @@ -113,7 +113,7 @@ extension InputKey {
///
/// - Parameter codingKey: The key to clean.
/// - Returns: The cleaned key.
static func clean<C: CodingKey>(codingKey: C) -> String {
static func clean(codingKey: CodingKey) -> String {
clean(codingKey: codingKey.stringValue)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//

#if os(macOS) && swift(>=5.6)
#if os(macOS) && swift(>=5.7)

import XCTest
import ArgumentParserTestHelpers
Expand Down

0 comments on commit 5535a95

Please sign in to comment.