[swift-users] Binary Operator '??' cannot be applied to operands of type 'T?' and 'Never'

Jacob Bandes-Storch jtbandes at gmail.com
Thu Oct 6 03:37:02 CDT 2016


Has there still not been a formal proposal for "Never as universal
subtype/bottom"? Someone please propose it :)

Jacob

On Sat, Nov 12, 2016 at 12:20 AM, Adrian Zubarev via swift-users <
swift-users at swift.org> wrote:

> I’ve build a custom operator for this: https://gist.github.com/
> DevAndArtist/dad641ee833e60b02fd1db2dbb488c6a
>
> infix operator ?! : NilCoalescingPrecedence
>
> func ?!<T>(optional: T?, noreturn: @autoclosure () -> Never) -> T {
>    switch optional {
>    case .some(let value):
>       return value
>    case .none:
>       noreturn()
>    }
> }
>
> // Usage
> let test: Int? = nil
>
> test ?! fatalError("Message")
>
>
>
> --
> Adrian Zubarev
> Sent with Airmail
>
> Am 6. Oktober 2016 um 05:35:53, Jonathan Hull via swift-users (
> swift-users at swift.org) schrieb:
>
> I used to be able to use ?? with fatalError(“Message”) to trap with a
> custom message in case of nil. This no longer works in Swift 3 (I think
> because of the update to never type)
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161006/0df064da/attachment.html>


More information about the swift-users mailing list