vatsal
(Vatsal)
1
Seemingly legal code in Swift 4.2:
extension Optional {
public func compact<T>() -> T? where Optional<Wrapped> == T?? {
return self ?? .none
}
public func compact<T>() -> T? where Optional<Wrapped> == T??? {
return (self ?? .none) ?? .none
}
public func compact<T>() -> T? where Optional<Wrapped> == T???? {
return ((self ?? .none) ?? .none) ?? .none
}
}
Now yields warnings in Swift 5. Is this a bug?
vatsal
(Vatsal)
2
Never mind, fixed it!
extension Optional {
public func compact<T>() -> T? where Wrapped == T? {
return self ?? .none
}
public func compact<T>() -> T? where Wrapped == T?? {
return (self ?? .none) ?? .none
}
public func compact<T>() -> T? where Wrapped == T??? {
return ((self ?? .none) ?? .none) ?? .none
}
}
1 Like