@@ -11,6 +11,9 @@ public struct ObjectData {
11
11
public let _transformer : any _ObjectData_Transformer
12
12
public let _rawData : [ String : AnyHashable ]
13
13
14
+ @usableFromInline internal static let _boolTrue = AnyHashable ( true )
15
+ @usableFromInline internal static let _boolFalse = AnyHashable ( false )
16
+
14
17
public init (
15
18
_transformer: any _ObjectData_Transformer ,
16
19
_rawData: [ String : AnyHashable ]
@@ -22,18 +25,18 @@ public struct ObjectData {
22
25
@inlinable public subscript( _ key: String ) -> ( any ScalarType ) ? {
23
26
guard let rawValue = _rawData [ key] else { return nil }
24
27
var value : AnyHashable = rawValue
25
-
26
- // Attempting cast to `Int` to ensure we always use `Int` vs `Int32` or `Int64` for consistency and ScalarType casting,
27
- // also need to attempt `Bool` cast first to ensure a bool doesn't get inadvertently converted to ` Int`
28
- switch value {
29
- case let boolVal as Bool :
28
+
29
+ // This check is based on AnyHashable using a canonical representation of the type-erased value so
30
+ // instances wrapping the same value of any type compare as equal. Therefore while Int(1) and Int(0)
31
+ // might be representable as Bool they will never equal Bool(true) nor Bool(false).
32
+ if let boolVal = value as? Bool , ( value == Self . _boolTrue || value == Self . _boolFalse ) {
30
33
value = boolVal
31
- case let intVal as Int :
32
- value = intVal
33
- default :
34
- break
34
+
35
+ // Cast to `Int` to ensure we always use `Int` vs `Int32` or `Int64` for consistency and ScalarType casting
36
+ } else if let intValue = value as? Int {
37
+ value = intValue
35
38
}
36
-
39
+
37
40
return _transformer. transform ( value)
38
41
}
39
42
0 commit comments