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-7339] Incorrect keypath error for invalid typecast #49887

Closed
swift-ci opened this issue Apr 3, 2018 · 3 comments
Closed

[SR-7339] Incorrect keypath error for invalid typecast #49887

swift-ci opened this issue Apr 3, 2018 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 3, 2018

Previous ID SR-7339
Radar rdar://problem/39142001
Original Reporter paiv (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)

Xcode 9.3

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

md5: 45aa5b2c9a05c9665672583ae8bf0723

Issue Description:

Given this code

class Some<T, V> {
    init(keyPath: KeyPath<T, ((V) -> Void)?>) {
    }
}

class Demo {
    var here: (() -> Void)?
}

and trying to create variable

let some = Some(keyPath: \Demo.here)

I'm getting this error

error: x.playground:4:32: error: type '_' has no member 'here'
let some = Some(keyPath: \Demo.here)
                               ^

Which is misleading, since Demo has member here.

If changed to

let kk = \Demo.here
let some = Some(keyPath: kk)

Error changes to

error: x.playground:5:26: error: cannot convert value of type 'ReferenceWritableKeyPath<Demo, (() -> Void)?>' to expected argument type 'KeyPath<_, ((_) -> Void)?>'
let some = Some(keyPath: kk)
                         ^~
@belkadan
Copy link
Contributor

belkadan commented Apr 3, 2018

@swift-ci create

@mdiep
Copy link
Contributor

mdiep commented Jun 5, 2018

Since it wasn't obvious to me:

The actual error here is because Demo.here takes 0 arguments but the Some.init takes a function that's generic over an argument V. That doesn't match a 0-arg function.

But that doesn't excuse the poor diagnostic.

This is still an issue in Apple Swift version 4.2 (swiftlang-1000.0.16.7 clang-1000.10.25.3).

@gregomni
Copy link
Collaborator

gregomni commented Aug 5, 2018

error improved in #18329

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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 in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants