Skip to content

Commit c9b9fbc

Browse files
authored
Merge pull request #4 from swhitty/swift-5.9.2
Enable ExistentialAny
2 parents 24b100f + a0a9e59 commit c9b9fbc

File tree

7 files changed

+67
-69
lines changed

7 files changed

+67
-69
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ on:
66
workflow_dispatch:
77

88
jobs:
9-
xcode_14_3_1:
9+
xcode_15_0_1:
1010
runs-on: macos-13
1111
env:
12-
DEVELOPER_DIR: /Applications/Xcode_14.3.1.app/Contents/Developer
12+
DEVELOPER_DIR: /Applications/Xcode_15.0.1.app/Contents/Developer
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v3
@@ -26,10 +26,10 @@ jobs:
2626
with:
2727
files: ./coverage_report.lcov
2828

29-
xcode_15:
29+
xcode_14_3_1:
3030
runs-on: macos-13
3131
env:
32-
DEVELOPER_DIR: /Applications/Xcode_15.0.app/Contents/Developer
32+
DEVELOPER_DIR: /Applications/Xcode_14.3.1.app/Contents/Developer
3333
steps:
3434
- name: Checkout
3535
uses: actions/checkout@v3
@@ -40,9 +40,9 @@ jobs:
4040
- name: Test
4141
run: swift test --skip-build
4242

43-
linux_swift_5_9:
43+
linux_swift_5_9_2:
4444
runs-on: ubuntu-latest
45-
container: swift:5.9
45+
container: swift:5.9.2
4646
steps:
4747
- name: Checkout
4848
uses: actions/checkout@v3
@@ -65,16 +65,3 @@ jobs:
6565
run: swift build --build-tests
6666
- name: Test
6767
run: swift test --skip-build
68-
69-
linux_swift_5_7:
70-
runs-on: ubuntu-latest
71-
container: swift:5.7
72-
steps:
73-
- name: Checkout
74-
uses: actions/checkout@v3
75-
- name: Version
76-
run: swift --version
77-
- name: Build
78-
run: swift build --build-tests
79-
- name: Test
80-
run: swift test --skip-build

Package.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.7
1+
// swift-tools-version:5.8
22
import PackageDescription
33

44
let package = Package(
@@ -15,12 +15,23 @@ let package = Package(
1515
targets: [
1616
.target(
1717
name: "KeyValueCoder",
18-
path: "Sources"
18+
path: "Sources",
19+
swiftSettings: .upcomingFeatures
1920
),
2021
.testTarget(
2122
name: "KeyValueCoderTests",
2223
dependencies: ["KeyValueCoder"],
23-
path: "Tests"
24+
path: "Tests",
25+
swiftSettings: .upcomingFeatures
2426
)
2527
]
2628
)
29+
30+
extension Array where Element == SwiftSetting {
31+
32+
static var upcomingFeatures: [SwiftSetting] {
33+
[
34+
.enableUpcomingFeature("ExistentialAny")
35+
]
36+
}
37+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![Build](https://github.com/swhitty/KeyValueCoder/actions/workflows/build.yml/badge.svg)](https://github.com/swhitty/KeyValueCoder/actions/workflows/build.yml)
22
[![CodeCov](https://codecov.io/gh/swhitty/KeyValueCoder/branch/main/graphs/badge.svg)](https://codecov.io/gh/swhitty/KeyValueCoder/branch/main)
3-
[![Swift 5.9](https://img.shields.io/badge/swift-5.7%20–%205.9-red.svg?style=flat)](https://developer.apple.com/swift)
3+
[![Swift 5.9](https://img.shields.io/badge/swift-5.8%20–%205.9-red.svg?style=flat)](https://developer.apple.com/swift)
44
[![License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://opensource.org/licenses/MIT)
55
[![Twitter](https://img.shields.io/badge/twitter-@simonwhitty-blue.svg)](http://twitter.com/simonwhitty)
66

Sources/KeyValueDecoder.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private extension KeyValueDecoder {
7878
struct Decoder: Swift.Decoder {
7979

8080
private let container: SingleContainer
81-
let codingPath: [CodingKey]
81+
let codingPath: [any CodingKey]
8282
let userInfo: [CodingUserInfoKey: Any]
8383

8484
init(container: SingleContainer) {
@@ -97,25 +97,25 @@ private extension KeyValueDecoder {
9797
return KeyedDecodingContainer(keyed)
9898
}
9999

100-
func unkeyedContainer() throws -> UnkeyedDecodingContainer {
100+
func unkeyedContainer() throws -> any UnkeyedDecodingContainer {
101101
let storage = try container.decode([Any].self)
102102
return UnkeyedContainer(codingPath: codingPath, storage: storage, userInfo: userInfo, nilDecodingStrategy: container.nilDecodingStrategy)
103103
}
104104

105-
func singleValueContainer() throws -> SingleValueDecodingContainer {
105+
func singleValueContainer() throws -> any SingleValueDecodingContainer {
106106
container
107107
}
108108
}
109109

110110
struct SingleContainer: SingleValueDecodingContainer {
111111

112-
let codingPath: [CodingKey]
112+
let codingPath: [any CodingKey]
113113
let userInfo: [CodingUserInfoKey: Any]
114114
let nilDecodingStrategy: NilDecodingStrategy
115115

116116
private var value: Any
117117

118-
init(value: Any, codingPath: [CodingKey], userInfo: [CodingUserInfoKey: Any], nilDecodingStrategy: NilDecodingStrategy) {
118+
init(value: Any, codingPath: [any CodingKey], userInfo: [CodingUserInfoKey: Any], nilDecodingStrategy: NilDecodingStrategy) {
119119
self.value = value
120120
self.codingPath = codingPath
121121
self.userInfo = userInfo
@@ -297,11 +297,11 @@ private extension KeyValueDecoder {
297297
struct KeyedContainer<Key: CodingKey>: KeyedDecodingContainerProtocol {
298298

299299
let storage: [String: Any]
300-
let codingPath: [CodingKey]
300+
let codingPath: [any CodingKey]
301301
private let userInfo: [CodingUserInfoKey: Any]
302302
private let nilDecodingStrategy: NilDecodingStrategy
303303

304-
init(codingPath: [CodingKey], storage: [String: Any], userInfo: [CodingUserInfoKey: Any], nilDecodingStrategy: NilDecodingStrategy) {
304+
init(codingPath: [any CodingKey], storage: [String: Any], userInfo: [CodingUserInfoKey: Any], nilDecodingStrategy: NilDecodingStrategy) {
305305
self.codingPath = codingPath
306306
self.storage = storage
307307
self.userInfo = userInfo
@@ -407,7 +407,7 @@ private extension KeyValueDecoder {
407407
return KeyedDecodingContainer<NestedKey>(keyed)
408408
}
409409

410-
func nestedUnkeyedContainer(forKey key: Key) throws -> UnkeyedDecodingContainer {
410+
func nestedUnkeyedContainer(forKey key: Key) throws -> any UnkeyedDecodingContainer {
411411
let container = try container(for: key)
412412
return try UnkeyedContainer(
413413
codingPath: container.codingPath,
@@ -417,25 +417,25 @@ private extension KeyValueDecoder {
417417
)
418418
}
419419

420-
func superDecoder() throws -> Swift.Decoder {
420+
func superDecoder() throws -> any Swift.Decoder {
421421
let container = SingleContainer(value: storage, codingPath: codingPath, userInfo: userInfo, nilDecodingStrategy: nilDecodingStrategy)
422422
return Decoder(container: container)
423423
}
424424

425-
func superDecoder(forKey key: Key) throws -> Swift.Decoder {
425+
func superDecoder(forKey key: Key) throws -> any Swift.Decoder {
426426
try Decoder(container: container(for: key))
427427
}
428428
}
429429

430430
struct UnkeyedContainer: UnkeyedDecodingContainer {
431431

432-
let codingPath: [CodingKey]
432+
let codingPath: [any CodingKey]
433433

434434
let storage: [Any]
435435
private let userInfo: [CodingUserInfoKey: Any]
436436
private let nilDecodingStrategy: NilDecodingStrategy
437437

438-
init(codingPath: [CodingKey], storage: [Any], userInfo: [CodingUserInfoKey: Any], nilDecodingStrategy: NilDecodingStrategy) {
438+
init(codingPath: [any CodingKey], storage: [Any], userInfo: [CodingUserInfoKey: Any], nilDecodingStrategy: NilDecodingStrategy) {
439439
self.codingPath = codingPath
440440
self.storage = storage
441441
self.userInfo = userInfo
@@ -541,13 +541,13 @@ private extension KeyValueDecoder {
541541
return result
542542
}
543543

544-
mutating func nestedUnkeyedContainer() throws -> UnkeyedDecodingContainer {
544+
mutating func nestedUnkeyedContainer() throws -> any UnkeyedDecodingContainer {
545545
let result = try Decoder(container: nextContainer()).unkeyedContainer()
546546
currentIndex = storage.index(after: currentIndex)
547547
return result
548548
}
549549

550-
mutating func superDecoder() -> Swift.Decoder {
550+
mutating func superDecoder() -> any Swift.Decoder {
551551
let container = SingleContainer(value: storage, codingPath: codingPath, userInfo: userInfo, nilDecodingStrategy: nilDecodingStrategy)
552552
return Decoder(container: container)
553553
}

Sources/KeyValueEncoder.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ private extension KeyValueEncoder {
145145

146146
final class Encoder: Swift.Encoder {
147147

148-
let codingPath: [CodingKey]
148+
let codingPath: [any CodingKey]
149149
let userInfo: [CodingUserInfoKey: Any]
150150
let nilEncodingStrategy: NilEncodingStrategy
151151

152-
init(codingPath: [CodingKey] = [], userInfo: [CodingUserInfoKey: Any], nilEncodingStrategy: NilEncodingStrategy) {
152+
init(codingPath: [any CodingKey] = [], userInfo: [CodingUserInfoKey: Any], nilEncodingStrategy: NilEncodingStrategy) {
153153
self.codingPath = codingPath
154154
self.userInfo = userInfo
155155
self.nilEncodingStrategy = nilEncodingStrategy
@@ -174,13 +174,13 @@ private extension KeyValueEncoder {
174174
return KeyedEncodingContainer(keyed)
175175
}
176176

177-
func unkeyedContainer() -> UnkeyedEncodingContainer {
177+
func unkeyedContainer() -> any UnkeyedEncodingContainer {
178178
let unkeyed = UnkeyedContainer(codingPath: codingPath, userInfo: userInfo, nilEncodingStrategy: nilEncodingStrategy)
179179
container = .provider(unkeyed.getEncodedValue)
180180
return unkeyed
181181
}
182182

183-
func singleValueContainer() -> SingleValueEncodingContainer {
183+
func singleValueContainer() -> any SingleValueEncodingContainer {
184184
let single = SingleContainer(codingPath: codingPath, userInfo: userInfo, nilEncodingStrategy: nilEncodingStrategy)
185185
container = .provider(single.getEncodedValue)
186186
return single
@@ -201,11 +201,11 @@ private extension KeyValueEncoder {
201201
final class KeyedContainer<K: CodingKey>: KeyedEncodingContainerProtocol {
202202
typealias Key = K
203203

204-
let codingPath: [CodingKey]
204+
let codingPath: [any CodingKey]
205205
private let userInfo: [CodingUserInfoKey: Any]
206206
private let nilEncodingStrategy: NilEncodingStrategy
207207

208-
init(codingPath: [CodingKey], userInfo: [CodingUserInfoKey: Any], nilEncodingStrategy: NilEncodingStrategy) {
208+
init(codingPath: [any CodingKey], userInfo: [CodingUserInfoKey: Any], nilEncodingStrategy: NilEncodingStrategy) {
209209
self.codingPath = codingPath
210210
self.storage = [:]
211211
self.userInfo = userInfo
@@ -307,18 +307,18 @@ private extension KeyValueEncoder {
307307
return KeyedEncodingContainer(keyed)
308308
}
309309

310-
func nestedUnkeyedContainer(forKey key: K) -> UnkeyedEncodingContainer {
310+
func nestedUnkeyedContainer(forKey key: K) -> any UnkeyedEncodingContainer {
311311
let path = codingPath.appending(key: key)
312312
let unkeyed = UnkeyedContainer(codingPath: path, userInfo: userInfo, nilEncodingStrategy: nilEncodingStrategy)
313313
storage[key.stringValue] = .provider(unkeyed.getEncodedValue)
314314
return unkeyed
315315
}
316316

317-
func superEncoder() -> Swift.Encoder {
317+
func superEncoder() -> any Swift.Encoder {
318318
return superEncoder(forKey: Key(stringValue: "super")!)
319319
}
320320

321-
func superEncoder(forKey key: Key) -> Swift.Encoder {
321+
func superEncoder(forKey key: Key) -> any Swift.Encoder {
322322
let path = codingPath.appending(key: key)
323323
let encoder = Encoder(codingPath: path, userInfo: userInfo, nilEncodingStrategy: nilEncodingStrategy)
324324
storage[key.stringValue] = .provider(encoder.getEncodedValue)
@@ -328,11 +328,11 @@ private extension KeyValueEncoder {
328328

329329
final class UnkeyedContainer: Swift.UnkeyedEncodingContainer {
330330

331-
let codingPath: [CodingKey]
331+
let codingPath: [any CodingKey]
332332
private let userInfo: [CodingUserInfoKey: Any]
333333
private let nilEncodingStrategy: NilEncodingStrategy
334334

335-
init(codingPath: [CodingKey], userInfo: [CodingUserInfoKey: Any], nilEncodingStrategy: NilEncodingStrategy) {
335+
init(codingPath: [any CodingKey], userInfo: [CodingUserInfoKey: Any], nilEncodingStrategy: NilEncodingStrategy) {
336336
self.codingPath = codingPath
337337
self.userInfo = userInfo
338338
self.nilEncodingStrategy = nilEncodingStrategy
@@ -437,14 +437,14 @@ private extension KeyValueEncoder {
437437
return KeyedEncodingContainer(keyed)
438438
}
439439

440-
func nestedUnkeyedContainer() -> UnkeyedEncodingContainer {
440+
func nestedUnkeyedContainer() -> any UnkeyedEncodingContainer {
441441
let path = codingPath.appending(index: count)
442442
let unkeyed = UnkeyedContainer(codingPath: path, userInfo: userInfo, nilEncodingStrategy: nilEncodingStrategy)
443443
storage.append(.provider(unkeyed.getEncodedValue))
444444
return unkeyed
445445
}
446446

447-
func superEncoder() -> Swift.Encoder {
447+
func superEncoder() -> any Swift.Encoder {
448448
let path = codingPath.appending(index: count)
449449
let encoder = Encoder(codingPath: path, userInfo: userInfo, nilEncodingStrategy: nilEncodingStrategy)
450450
storage.append(.provider(encoder.getEncodedValue))
@@ -454,11 +454,11 @@ private extension KeyValueEncoder {
454454

455455
final class SingleContainer: SingleValueEncodingContainer {
456456

457-
let codingPath: [CodingKey]
457+
let codingPath: [any CodingKey]
458458
private let userInfo: [CodingUserInfoKey: Any]
459459
private let nilEncodingStrategy: NilEncodingStrategy
460460

461-
init(codingPath: [CodingKey], userInfo: [CodingUserInfoKey: Any], nilEncodingStrategy: NilEncodingStrategy) {
461+
init(codingPath: [any CodingKey], userInfo: [CodingUserInfoKey: Any], nilEncodingStrategy: NilEncodingStrategy) {
462462
self.codingPath = codingPath
463463
self.userInfo = userInfo
464464
self.nilEncodingStrategy = nilEncodingStrategy
@@ -547,21 +547,21 @@ private extension KeyValueEncoder {
547547
}
548548
}
549549

550-
extension Array where Element == CodingKey {
550+
extension Array where Element == any CodingKey {
551551

552-
func appending(key codingKey: CodingKey) -> [CodingKey] {
552+
func appending(key codingKey: any CodingKey) -> [any CodingKey] {
553553
var path = self
554554
path.append(codingKey)
555555
return path
556556
}
557557

558-
func appending(index: Int) -> [CodingKey] {
558+
func appending(index: Int) -> [any CodingKey] {
559559
var path = self
560560
path.append(AnyCodingKey(intValue: index))
561561
return path
562562
}
563563

564-
func makeKeyPath(appending key: CodingKey? = nil) -> String {
564+
func makeKeyPath(appending key: (any CodingKey)? = nil) -> String {
565565
var path = map(\.keyPath)
566566
if let key = key {
567567
path.append(key.keyPath)

Tests/KeyValueDecoderTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ private extension KeyValueDecoder {
809809
return proxy.result!
810810
}
811811

812-
static func decodeUnkeyedValue<T>(from value: [Any], with closure: @escaping (inout UnkeyedDecodingContainer) throws -> T) throws -> T {
812+
static func decodeUnkeyedValue<T>(from value: [Any], with closure: @escaping (inout any UnkeyedDecodingContainer) throws -> T) throws -> T {
813813
let proxy = StubDecoder.Proxy { decoder in
814814
var container = try decoder.unkeyedContainer()
815815
return try closure(&container)
@@ -835,20 +835,20 @@ private extension CodingUserInfoKey {
835835
private struct StubDecoder: Decodable {
836836

837837
final class Proxy<T> {
838-
private let closure: (Decoder) throws -> T
838+
private let closure: (any Decoder) throws -> T
839839
private(set) var result: T?
840840

841-
init(_ closure: @escaping (Decoder) throws -> T) {
841+
init(_ closure: @escaping (any Decoder) throws -> T) {
842842
self.closure = closure
843843
}
844844

845-
func decode(from decoder: Decoder) throws {
845+
func decode(from decoder: any Decoder) throws {
846846
self.result = try closure(decoder)
847847
}
848848
}
849849

850-
init(from decoder: Decoder) throws {
851-
let closure = decoder.userInfo[.decoder] as! (Decoder) throws -> Void
850+
init(from decoder: any Decoder) throws {
851+
let closure = decoder.userInfo[.decoder] as! (any Decoder) throws -> Void
852852
try closure(decoder)
853853
}
854854
}

0 commit comments

Comments
 (0)