[swift-users] ?? operator question

Marius-Ioan Serban marius.ioan.serban at gmail.com
Mon Apr 18 05:21:13 CDT 2016


Because in your example T = CustomStringConvertible

On Mon, Apr 18, 2016 at 10:51 AM, tuuranton--- via swift-users <
swift-users at swift.org> wrote:

> Why does this compile?
>
> let t1: Int? = 2
> print(t1 ?? "asdf")
>
> The type of ?? is this:
>
> @warn_unused_result
> public func ??<T>(optional: T?, @autoclosure defaultValue: () throws -> T)
> rethrows -> T
>
> The type syas that T must be the same type throughout. But above I could
> successfully use Int? and then String. Why?
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>


-- 
Marius Serban
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160418/daef22da/attachment.html>


More information about the swift-users mailing list