Skip to content

Commit 1f982b2

Browse files
AdamShareAdam Share
authored andcommitted
Update to Swift 6.0 and fix Sendable conformance
- Update swift-tools-version to 6.0 - Make error enums fully Sendable compliant - Use String types instead of Any/CodingKey in error cases
1 parent 1688f56 commit 1f982b2

4 files changed

Lines changed: 24 additions & 24 deletions

File tree

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.7
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -10,7 +10,7 @@ let package = Package(
1010
.library(
1111
name: "DictionaryEncoder",
1212
targets: ["DictionaryEncoder"]
13-
),
13+
)
1414
],
1515
dependencies: [
1616
// Dependencies declare other packages that this package depends on.

Sources/DictionaryEncoder/DictionaryDecoder.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ import Combine
1818
import Foundation
1919

2020
/// Errors from `DictionaryDecoder`
21-
public enum DictionaryDecoderError: LocalizedError {
21+
public enum DictionaryDecoderError: LocalizedError, Sendable {
2222
/// The dictionary value could not be decoded to the expected type.
23-
case typeMismatch(expected: Any.Type, actual: Any, codingPath: [CodingKey])
23+
case typeMismatch(expected: String, actual: String, codingPath: [String])
2424
/// A required key was not found in the dictionary.
25-
case keyNotFound(CodingKey, codingPath: [CodingKey])
25+
case keyNotFound(String, codingPath: [String])
2626
/// The value was null or missing when a non-optional was expected.
27-
case valueNotFound(Any.Type, codingPath: [CodingKey])
27+
case valueNotFound(String, codingPath: [String])
2828

2929
public var errorDescription: String? {
3030
switch self {
3131
case let .typeMismatch(expected, actual, codingPath):
32-
let path = codingPath.map(\.stringValue).joined(separator: ".")
33-
return "Type mismatch at '\(path)': expected \(expected) but found \(type(of: actual))."
32+
let path = codingPath.joined(separator: ".")
33+
return "Type mismatch at '\(path)': expected \(expected) but found \(actual)."
3434
case let .keyNotFound(key, codingPath):
35-
let path = codingPath.map(\.stringValue).joined(separator: ".")
36-
return "Key '\(key.stringValue)' not found at '\(path)'."
35+
let path = codingPath.joined(separator: ".")
36+
return "Key '\(key)' not found at '\(path)'."
3737
case let .valueNotFound(type, codingPath):
38-
let path = codingPath.map(\.stringValue).joined(separator: ".")
38+
let path = codingPath.joined(separator: ".")
3939
return "Value of type \(type) not found at '\(path)'."
4040
}
4141
}

Sources/DictionaryEncoder/DictionaryEncoder.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import Combine
1818
import Foundation
1919

2020
/// Errors from `DictionaryEncoder`
21-
public enum DictionaryEncoderError: LocalizedError {
21+
public enum DictionaryEncoderError: LocalizedError, Sendable {
2222
/// The type was not encoded to a keyed container so a dictionary could not be returned.
23-
case notKeyedContainer(Any)
23+
case notKeyedContainer(String)
2424

2525
public var errorDescription: String? {
2626
switch self {
27-
case let .notKeyedContainer(value):
28-
return "\(value) does not encode to a keyed container."
27+
case let .notKeyedContainer(typeDescription):
28+
return "\(typeDescription) does not encode to a keyed container."
2929
}
3030
}
3131
}
@@ -65,9 +65,9 @@ public final class DictionaryEncoder: TopLevelEncoder {
6565
case .keyed:
6666
return container.dictionary
6767
case .singleValue:
68-
throw DictionaryEncoderError.notKeyedContainer(value)
68+
throw DictionaryEncoderError.notKeyedContainer(String(describing: type(of: value)))
6969
case .unkeyed:
70-
throw DictionaryEncoderError.notKeyedContainer(value)
70+
throw DictionaryEncoderError.notKeyedContainer(String(describing: type(of: value)))
7171
}
7272
}
7373

Tests/DictionaryEncoderTests/DictionaryDecoderTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,9 @@ struct DictionaryDecoderTests {
643643
@Test("DictionaryDecoderError type mismatch description")
644644
func decoderErrorTypeMismatchDescription() throws {
645645
let error = DictionaryDecoderError.typeMismatch(
646-
expected: String.self,
647-
actual: 123,
648-
codingPath: [AnyCodingKey("testKey")]
646+
expected: "String",
647+
actual: "Int",
648+
codingPath: ["testKey"]
649649
)
650650
let description = error.errorDescription
651651
#expect(description != nil)
@@ -656,8 +656,8 @@ struct DictionaryDecoderTests {
656656
@Test("DictionaryDecoderError key not found description")
657657
func decoderErrorKeyNotFoundDescription() throws {
658658
let error = DictionaryDecoderError.keyNotFound(
659-
AnyCodingKey("missingKey"),
660-
codingPath: [AnyCodingKey("parent")]
659+
"missingKey",
660+
codingPath: ["parent"]
661661
)
662662
let description = error.errorDescription
663663
#expect(description != nil)
@@ -667,8 +667,8 @@ struct DictionaryDecoderTests {
667667
@Test("DictionaryDecoderError value not found description")
668668
func decoderErrorValueNotFoundDescription() throws {
669669
let error = DictionaryDecoderError.valueNotFound(
670-
String.self,
671-
codingPath: [AnyCodingKey("path")]
670+
"String",
671+
codingPath: ["path"]
672672
)
673673
let description = error.errorDescription
674674
#expect(description != nil)

0 commit comments

Comments
 (0)