[SR-9818] Compile error is wrong when calling generic function with an argument of the wrong type #52235
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler itself
key paths
Feature: key paths (both native and Objective-C)
type checker
Area → compiler: Semantic analysis
Attachment: Download
Environment
Swift 4.2
Additional Detail from JIRA
md5: a9dabc9d51d41c18b92d4aa8090e6384
Issue Description:
When I try to call the generic function below, if I pass the wrong type for the second parameter (a String instead of an Int), the compile error is wrong. It says there is a problem with the first parameter.
The error is:
Key path value type 'Equipment?' cannot be converted to contextual type 'NSManagedObject?'
I think the error should be something like:
Cannot convert value of type 'String' to expected argument of type 'Int'
Here is the code (sorry if the formatting is wrong, there is also a playground attached):
import CoreData``class
Equipment: NSManagedObject {
{{}}}
class Injury {
{{ init() {}}
{{ var equipment: Equipment?}}
{{ func set<T: NSManagedObject>(propertyAt keyPath: ReferenceWritableKeyPath<Injury, T?>, toValueWithServerID serverID: Int {}}
{{}}}
let injury = Injury()
injury.set(propertyAt: \Injury.equipment, toValueWithServerID: "foo")
The text was updated successfully, but these errors were encountered: