Swift 1.2: Misleading "could not find an overload" compiler error

Originator:ajpike
Number:rdar://20099385 Date Originated:09-Mar-2015 05:19 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.3b2
Classification:UI/Usability Reproducible:Always
 
Summary:
When using a ternary operator, the error “Could not find an overload for == that accepts the supplied arguments” will display when the problem is actually not related to the == operator at all.

Steps to Reproduce:
Open the attached playground, and note the code:

let number: Int = 1
let text: String = number == 0 ? "" : number

Of course, the above code doesn’t build because Swift can’t automatically cast number to a String. The error message is very confusing however: it complains about == and highlights the whole expression. If you break out the equality check, you get more helpful, but still confusing errors:

let boolean: Bool = number == 0
let text2: String = boolean ? "" : number

This will give you “_ is not convertible to StringLiteralConvertible” indicating the empty string. Hidden inside that is the actually useful error “Int is not convertible to String”, though both errors in Xcode indicate the “” as the issue.

Expected Results:
It should show the error “Int is not convertible to String” indicated at the use of “number” in the ternary expression.

Actual Results:
The error message “Could not find an overload for ‘==‘ that accepts the supplied arguments”

Regression:
Tested on Swift 1.2 in Xcode 6.3b2.

Comments

This is fixed in Swift 2.0 :)


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!