[swift-evolution] [Draft] Abolish IUO type
cwillmore at apple.com
Wed Mar 16 23:01:16 CDT 2016
> On Mar 16, 2016, at 5:34 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
>> The most significant one is that I think that describing this in terms of an IUO attribute (which is an internal implementation detail) makes the proposal more confusing than necessary for the non-compiler hackers. :-)
> For what it's worth, I actually find it really helpful to have a way to talk about these kinds of features without sugar. I spent most of this proposal going "So, does that mean `Int!` is now `@implicitly_unwrapped Optional<Int>`?”
Not quite. It means “let x: Int!” is now “@implicitly_unwrapped let x: Int?” (supposing one could spell the attribute out like that). That is, the IUO attribute is attached to the declaration of the variable instead of its type.
> It's particularly important in this case because `!` implies `?`; there's a lot of magic going on here. Without a completely unambiguous way to write about this behavior, it's hard to talk about it precisely.
> For instance, I have two questions for the proposal's author:
> * Would the declaration `Int?!` mean `@implicitly_unwrapped Optional<Int>` or `@implicitly_unwrapped Optional<Optional<Int>>`?
The latter, modulo the correction above.
> * You say that things like `[Int!]` and `(Int!, Int!)` (`Array<@implicitly_unwrapped Optional<Int>>` and `(@implicitly_unwrapped Optional<Int>, @implicitly_unwrapped Optional<Int>)`) are illegal; are `Int!?` and `Int!!` (`Optional<@implicitly_unwrapped Optional<Int>>` and `@implicitly_unwrapped Optional<@implicitly_unwrapped Optional<Int>>`) illegal as well? (Actually, having written this out explicitly, I'm now fairly confident of the answer: yes, they are illegal.)
Correct; they’re illegal because the “!” token doesn’t appear at the outermost level and therefore there’s no decl to attach the IUO attribute to.
— Chris W.
> These kinds of questions are hard to pose unless we have a language to discuss them in, even if that language is rarely actually used when we write code.
> Brent Royal-Gordon
More information about the swift-evolution