Swift doesn't allow one variadic argument function to call another using its own arguments array.

Originator:armadsen
Number:rdar://17132238 Date Originated:03-Jun-2014 04:52 PM
Status:Closed Resolved:10-Jun-2014 05:20 PM
Product:Developer Tools Product Version:Xcode6-Beta (6A215l)
Classification:Enhancement Reproducible:Always
 
Summary:
In Swift, if you define a function that takes a variable number of arguments, it is not possible to pass those arguments (as an array) to another function with a variable number of arguments inside the body of the first function.

Steps to Reproduce:
1. Define a function that takes a variable number of arguments.
2. Define a second function that also takes a variable number of arguments.
3. Inside the body of the second function, call the first function by passing the calling functions own array of arguments to it.

Expected Results:
Swift recognizes that the items in the array of arguments being passed to function 1 are meant to be used as arguments to it.

Actual Results:
A compiler error is produced. “Could not find an overload for ‘__conversion’ that accepts the supplied arguments.”

Notes:
The code below demonstrates this problem:

func sumOf(numbers: Int...) -> Int {
	var sum = 0
	for number in numbers {
		sum += number
	}
	return sum
}
sumOf(42, 597, 12)

func averageOf(numbers: Int...) -> Float {
	let sum = sumOf(numbers)
	return Float(sum) / Float(numbers.count)
}

averageOf(42, 597, 12, 18)

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!