Swift error for argument not conforming to protocol is misleading

Originator:sforteln
Number:rdar://20789322 Date Originated:May 1 2015
Status:Open Resolved:
Product:Developer tools Product Version:Xcode 6.3 (6D570)
Classification: Reproducible:Always
 
Summary:
In swift 1.2 when a function takes a type that must conform to a protocol as its argument is passed a type that does not conform to the protocol the error message does not direct the user to the root problem.  

example from attached playground
func create<T: ProtocolA>(T.Type) -> T? {
    return T()
}
let foo = create(classA)// works: classA conforms to ProtocolA
let bar = create(String)// error since String does not conform to ProtocolA but the error is the misleading "Cannot invoke 'create' with no arguments"

Steps to Reproduce:
Open the attached playground in Xcode 6.3 (6D570) and note the error on line 20.  

let bar = create(String) //error "Cannot invoke 'create' with no arguments"

Expected Results:
Since the argument on line 20 does not conform to the protocol an error is expected.  But it would be helpful if the error was a bit more helpful.  Something like "Argument does not conform to 'ProtocolA'"


Actual Results:
The error message is "Cannot invoke 'create' with no arguments" which is confusing since I did supply an argument and in the previous line supplying a type worked fine.

Version:
Xcode 6.3 (6D570)
Swift 1.2
OS X 10.10.3

Notes:
Contents of playground
protocol ProtocolA {
    init()
}

class classA : ProtocolA {
    required init() { }
}

func create<T: ProtocolA>(T.Type) -> T? {
    return T()
}

let foo = create(classA)
let bar = create(String)


Configuration:
in Xcode 6.3 (6D570) with Swift 1.2. Both in a playground and building an iOS app.

Attachments:
'no_args.playground.zip' and 'genericsError.png' were successfully uploaded.

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!