Avatar
omochimetaru 3/8/2019 6:49 AM
@swift-5.0.3 struct IntError : Error { var value: Int } struct StringError : Error { var value: String } extension Error { mutating func assign(other: Self) { print("assign:") print("self type=", type(of: self)) print("other type=", type(of: other)) print("dump self") dump(self) print("dump other") dump(other) switch self { case is IntError: print("self is IntError") case is StringError: print("self is StringError") default: break } print("---") self = other } } func dispatchAssign<E: Error>(_ a: inout E, _ b: E) { a.assign(other: b) } func main() { let e0 = IntError(value: 3) var e0e: Error = e0 dump(e0e) let e1 = StringError(value: "a") let e1e: Error = e1 dispatchAssign(&e0e, e1e) dump(e0e) } main()