[swift-evolution] [Draft] Abolish IUO type

Chris Lattner clattner at apple.com
Mon Mar 21 19:57:19 CDT 2016


On Mar 18, 2016, at 11:36 AM, Chris Willmore via swift-evolution <swift-evolution at swift.org> wrote:
>> typedef void (^CallbackBlock)(FDataSnapshot *snapshot);
>> 
>> The parameter in the block gets converted into a IUO, I ended up releasing an app that crashed due to that IUO being nil.
>> 
>> The code that crashed was something like this
>> 
>> object.observe {
>> $0.doSomething()
>> }
>> 
>> There is no way to tell that the $0 was a IUO. The compiler didn't force me to confirm in it in some way using a ! and unless I remembered to check the header I would have a crash.
>> 
>> How would this work under your proposal ?
> 
> This is a great question. I think it would make the most sense to import the CallbackBlock type as (FDataSnapshot?) -> (), since there’s no decl to hang the IUO attribute onto. Then $0 ends up with type FDataSnapshot? (i.e. Optional<FDataSnapshot>), and the compiler would not allow you to simply call doSomething() on $0 without forcing it first.

I agree that this is the most straight-forward thing to do.  Chris, please add a mention of this to the proposal so that the review discussion considers it.  Thanks!

-Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160321/fe988fc4/attachment.html>


More information about the swift-evolution mailing list