Skip to content

Commit 8b441f3

Browse files
authored
Merge pull request #99 from tayloraswift/fix-sendable
Fix #95
2 parents e5a8ddc + 9c7b07a commit 8b441f3

File tree

3 files changed

+20
-29
lines changed

3 files changed

+20
-29
lines changed

Sources/JSONAST/JSON.IntegerOverflowError.swift

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,12 @@ extension JSON {
33
///
44
/// This error is thrown by decoders, and is different from
55
/// `Grammar.Pattern.IntegerOverflowError`, which is thrown by the parser.
6-
public struct IntegerOverflowError: Error, Sendable {
6+
public struct IntegerOverflowError<Representation>: NumericOverflowError, Equatable {
77
/// The number literal that could not be converted.
88
public let number: Number
99

10-
/// The metatype of the desired integer type.
11-
public let overflows: any FixedWidthInteger.Type
12-
13-
public init(number: Number, overflows: any FixedWidthInteger.Type) {
10+
public init(number: Number) {
1411
self.number = number
15-
self.overflows = overflows
1612
}
1713
}
1814
}
19-
extension JSON.IntegerOverflowError {
20-
@available(
21-
swift, deprecated: 5.7,
22-
message: "use the more strongly-typed 'overflows' property"
23-
) public var type: Any.Type { self.overflows }
24-
}
25-
extension JSON.IntegerOverflowError: Equatable {
26-
public static func == (lhs: Self, rhs: Self) -> Bool {
27-
lhs.equals(number: rhs.number, overflows: rhs.overflows)
28-
}
29-
30-
private func equals<Integer>(number: JSON.Number, overflows _: Integer.Type) -> Bool
31-
where Integer: FixedWidthInteger {
32-
self.number == number && self.overflows is Integer.Type
33-
}
34-
}
35-
extension JSON.IntegerOverflowError: CustomStringConvertible {
36-
public var description: String {
37-
"integer literal '\(number)' overflows decoded type '\(self.overflows)'"
38-
}
39-
}

Sources/JSONAST/JSON.Node.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ extension JSON.Node {
174174
return nil
175175
}
176176
guard let integer: Integer = number.as(Integer.self) else {
177-
throw JSON.IntegerOverflowError.init(number: number, overflows: Integer.self)
177+
throw JSON.IntegerOverflowError<Integer>.init(number: number)
178178
}
179179
return integer
180180
}
@@ -201,7 +201,7 @@ extension JSON.Node {
201201
return nil
202202
}
203203
guard let integer: Integer = number.as(Integer.self) else {
204-
throw JSON.IntegerOverflowError.init(number: number, overflows: Integer.self)
204+
throw JSON.IntegerOverflowError<Integer>.init(number: number)
205205
}
206206
return integer
207207
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extension JSON {
2+
/// An integer overflow occurred while converting a number literal to a desired type.
3+
///
4+
/// This error is thrown by decoders, and is different from
5+
/// `Grammar.Pattern.IntegerOverflowError`, which is thrown by the parser.
6+
public protocol NumericOverflowError<Representation>: Error, CustomStringConvertible {
7+
associatedtype Representation
8+
/// The number literal that could not be converted.
9+
var number: Number { get }
10+
}
11+
}
12+
extension JSON.NumericOverflowError {
13+
public var description: String {
14+
"numeric literal '\(self.number)' overflows decoded type '\(Representation.self)'"
15+
}
16+
}

0 commit comments

Comments
 (0)