[swift-evolution] Implicit Optionals for Tuples & Tuples as Function Parameter

Muhammad Tahir Vali tahir.vali13 at gmail.com
Fri Nov 11 14:50:28 CST 2016


Thank you. Overlooked that in the Swift 3 release notes.

On Fri, Nov 11, 2016 at 3:43 PM, John McCall <rjmccall at apple.com> wrote:

> On Nov 11, 2016, at 11:54 AM, Muhammad Tahir Vali via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> Im curious to know the reasoning behind why implicit-wrapped optionals
> aren't allowed when creating tuples. Below is an example with type aliases
> and anonymous tuples.
>
> ex.
> typealias Name = (first: String!, middle: String?, last: String!)
> typealias Name = (first: String!, middle: String?, last: String!)!
> var name : (first: String!, middle: String?, last: String!)
> var name : (first: String!, middle: String?, last: String!)!
>
> error from all 4 examples above:
> Implicitly unwrapped optionals are only allowed at top level and as
> function results
>
>
> This is intentionally-designed behavior.  Preventing IUO at arbitrary
> locations was SE-0054:
>   https://github.com/apple/swift-evolution/blob/master/
> proposals/0054-abolish-iuo.md
>
> I also noticed that I can modify tuples using functions ONLY if I use
> *inout*.
>
> func name(Person : inout (first: String?, middle: String?, last: String?))
> {
>     Person.first = "John"
>     Person.last = "Doe"
> }
>
> OR
>
> func name(Person : inout Name) {
>     Person.first = "John"
>     Person.last = "Doe"
>
> }
>
> This is because tuples are passed into functions as 'let' constants. Why
> not add the ability to modify a copy of the tuple inside the function ?
>
>
> We used to allow "var" parameters, but they were removed in SE-0003:
>   https://github.com/apple/swift-evolution/blob/master/
> proposals/0003-remove-var-parameters.md
>
> Tuples are values like any other; I don't know why they would warrant a
> special exception to that rule.
>
> John.
>



-- 
Best Regards,

Muhammad T. Vali
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161111/b2733b6c/attachment.html>


More information about the swift-evolution mailing list