[swift-evolution] [Discussion] Enforce argument labels on tuples

Adrian Zubarev adrian.zubarev at devandartist.com
Wed Apr 20 08:23:22 CDT 2016

I would like to discuss about the following topic.

Wouldn't it be better to enforce argument labels on tuples types, if the tuple type defines them?


func foo(tuple: (a: Int, b: Int)) { /* do something */ }

let test1 = (10, 100)
let test2: (a: Int, c: Int) = test
let test3: (Int, Int) = test2


cannot convert value of type '(a: Int, c: Int)' 
to expected argument type '(a: Int, b: Int)'


Function `foo` awaits a tuple of type `(a: Int, b: Int)` but `test1` and `test3` are both just of type `(Int, Int)`.
As expected `test2` will raise an error because it has indeed a wrong type `(a: Int, c: Int)`.

I'd suggest to enforce argument labeling on tuple types for better readability, because wasn't it the idea behind labels inside tuples?

`foo(test1)` should raise an error `cannot convert value of type '(Int, Int)' to expected argument type '(a: Int, b: Int)'` as long as `test1` is not written like `let test1 = (a: 10, b: 100)` or `let test1: (a: Int, b: Int) = (a: 10, b: 100)`

This will impact current codebase if you used labels but provided tuples without labels like the example above. The migrator could solve this by providing labels automatically to tuples where this error occurs.

I'm not good at writing proposals for the GitHub repository at all, so if the community likes this idea, I'd be glad to see some help for this little proposal.

Adrian Zubarev
Sent with Airmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160420/4d369c52/attachment.html>

More information about the swift-evolution mailing list