Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-9818] Compile error is wrong when calling generic function with an argument of the wrong type #52235

Open
swift-ci opened this issue Jan 30, 2019 · 1 comment
Assignees
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

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-9818
Radar None
Original Reporter justin.garcia (JIRA User)
Type Bug

Attachment: Download

Environment

Swift 4.2

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, KeyPaths, TypeChecker
Assignee @xedin
Priority Medium

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")

@belkadan
Copy link
Contributor

Still occurs on master. cc @xedin

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants