THRIFT-5195: Handle Thrift union type sending for Swift
Client: Swift
Patch: Eric Chen
This closes #2154
diff --git a/lib/swift/Sources/TStruct.swift b/lib/swift/Sources/TStruct.swift
index f120833..d0a1a4b 100644
--- a/lib/swift/Sources/TStruct.swift
+++ b/lib/swift/Sources/TStruct.swift
@@ -62,7 +62,7 @@
for (propName, propValue) in mirror.children {
guard let propName = propName else { continue }
- if let tval = unwrap(any: propValue) as? TSerializable, let id = Self.fieldIds[propName] {
+ if let tval = unwrap(any: propValue, parent: mirror) as? TSerializable, let id = Self.fieldIds[propName] {
try block(propName, tval, id)
}
}
@@ -78,10 +78,10 @@
/// - parameter any: Any instance to attempt to unwrap
///
/// - returns: Unwrapped Any as Optional<Any>
- private func unwrap(any: Any) -> Any? {
+ private func unwrap(any: Any, parent: Mirror) -> Any? {
let mi = Mirror(reflecting: any)
- if mi.displayStyle != .optional { return any }
+ if parent.displayStyle != .enum && mi.displayStyle != .optional { return any }
if mi.children.count == 0 { return nil }
let (_, some) = mi.children.first!