Swift: Unclear error message when using result of incorrectly called function with arithmetic operator

Originator:armadsen
Number:rdar://17132688 Date Originated:03-Jun-2014 05:06 PM
Status:Closed Resolved:19-Feb-2015
Product:Developer Tools Product Version:Xcode6-Beta (6A215l)
Classification:UI/Usability Reproducible:Always
 
Summary:
My motivation for filing this bug report is a problem discovered concurrently with rdar://17132238. When using the result of an incorrectly called function as the input to an arithmetic operator, Xcode obscures the underlying error with a cryptic error about the operator.

Steps to Reproduce:
1. Enter the following code in a playground:

 For example, this code:

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

func averageOf(numbers: Int...) -> Float {
	return Float(sumOf(numbers)) / Float(numbers.count)
}
averageOf(1, 2, 3)



Expected Results:
An error message informing the programmer that sumOf() is being called with a bad argument, as will be seen if that call is made on its own line. In that case, the error message will be “Could not find an overload for ‘__conversion’ that accepts the supplied arguments”, which is more descriptive of the actual error here (though still not great).

Actual Results:
averageOf()’s return statement provokes the following error message: “Could not find an overload for ‘/‘ that accepts the supplied arguments”.

Notes:
The following code 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 {
	return Float(sumOf(numbers)) / 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!