[swift-evolution] [Review] SE-0054: Abolish ImplicitlyUnwrappedOptional type

Jose Cheyo Jimenez cheyo at masters3d.com
Fri Mar 25 20:37:29 CDT 2016

Ah got it. I missed that part. [1]

> On Mar 25, 2016, at 4:16 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
>> I do have a question. 
>> let x: Int! = 5
>> let y = x
>> let a = x ?? 1 // would this still work? 

This should work then. I guess I never thought about safely “unwrapping" an IUO in swift2 but it works. 


>> Or would it auto unwrapping always? meaning when .some `a = 5` or crash when .none? 
>> I am assuming that x is `Int?` that autounwraps. Just curious if autounwraps only happen on assignment like in `y = x`
> I believe that, in this example, `y` is of type `Int?`, that is, a non-autounwrapped optional. An autounwrapped optional is only unwrapped if Swift cannot make the code type-check without unwrapping it.
> -- 
> Brent Royal-Gordon
> Architechies
[1] “x is declared as an IUO, but because the initializer for y type checks correctly as an optional, y will be bound as typeInt?. However, the initializer for z does not type check with x declared as an optional (there's no overload of + that takes an optional), so the compiler forces the optional and type checks the initializer as Int."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160325/545d7f30/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-4.png
Type: image/png
Size: 13693 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160325/545d7f30/attachment.png>

More information about the swift-evolution mailing list