Adding Sugar for Preconditions and Guards

This thread is giving me SE-0217 vibes. I feel that syntax could be quite fitting for this proposal (considering the existence of ?? as a "soft-fallback"):

let foo = foo !! preconditionFailure("Foo must not be nil")

This also allows flexibility for other cases such as:

let foo = foo !! fatalError("Foo must not be nil")

And in general, any function yielding -> Never.

I am aware of the decision to reject the original proposal 3 years ago, however most of what was said to be the reasons for it back then has fallen short by now and we're still dealing with this same issue in Swift nowadays, so I feel a review of this situation is due.

1 Like