Ah got it. I missed that part. [1]
> On Mar 25, 2016, at 4:16 PM, Brent Royal-Gordon <br...@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.
Thanks!
>> 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."
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution