Swift problems with tuples in argument lists

Originator:kristopherdjohnson
Number:rdar://17222623 Date Originated:08-Jun-2014 11:03 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6
Classification:Serious Bug Reproducible:Always
 
The code below was entered in a Swift playground. It creates an array of (Int, String) tuples, and then tried various ways to call Array.append to add tuples to the list.

The first surprising behavior is that one can't write 'a.append((1, "One")'. The result is a compiler error "Missing argument for parameter #2 in call". The workaround is to write 'a.append(1, "One")', so apparently a function that takes a tuple argument must be called as if that tuple is really the argument list.

The second surprising behavior is that it seems impossible to pass array elements as arguments to a method that takes tuples. As seen below, trying the "treat it as a parameter list" trick results in the "missing argument for parameter #2" error, and adding parentheses results in a "Could not find user-defined conversion from type 'Int' to type '(Int, String)'" error. The workaround I found was to assign the tuple to a constant and then pass that constant to the method.

The below code can be pasted into a playground to see the results.

var a = Array<(Int, String)>()

var aInt: Int[] = [1, 2, 3]
var aString: String[] = ["One", "Two", "Three"]

// This fails with compile error:
// "Missing argument for parameter #2 in call"
a.append((1, "One"))

// This works
a.append(1, "One")
a

// This works
let t = (aInt[0], aString[0])
a.append(t)

// This fails with compile error:
// "Could not find a user-defined conversion from type 'Int' to type '(Int, String'"
a.append(aInt[0], aString[0])

// This fails with compile error:
// "Missing argument for parameter #2 in call"
a.append((aInt[0], aString[0]))

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!