Pitch: Deprecate strange interpolations in Swift 4.2

You probably are aware of this, but #2 doesn't compile (contrary to what you said). I've tested the following program in Xcode 9.4, Xcode 10 beta and dev snapshot 2018-06-14), and for all three compiler versions:

let firstName = "Ada"
print("Hello, \(first: firstName)!")                    // #2

Results in:

error: type of expression is ambiguous without more context

But there are other ways of forming a single-element tuple:

let x = (label: 123).label

This compiles in all of the above three versions of the compiler.


And the following one (which succeeds in instantiating a single-element tuple constant and variable and using the label on them rather than just on the literal tuple expression as above) will only compile with Xcode 10 beta and later:

let c = (label: 123)
let twice = c.label + c.label
print(twice) // 246
var v = c
v.label = 3
print(v.label) // 3

Which makes me wonder if work has begun to remove the weird exception of banning single-element tuples.

1 Like