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-5688] Unhelpful diagnostic when missing a ? in a KeyPath expression #48258

Closed
mdiep opened this issue Aug 15, 2017 · 6 comments
Closed

[SR-5688] Unhelpful diagnostic when missing a ? in a KeyPath expression #48258

mdiep opened this issue Aug 15, 2017 · 6 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

Comments

@mdiep
Copy link
Contributor

mdiep commented Aug 15, 2017

Previous ID SR-5688
Radar None
Original Reporter @mdiep
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 9.0.0 ß5

Apple Swift version 4.0 (swiftlang-900.0.59 clang-900.0.34.2)

Target: x86_64-apple-macosx10.9

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

md5: c71e85e71edfd0319c05a4dfe3d8443e

Issue Description:

This code:

struct A {
    var b: B?
}

struct B {
    var c: Int
}

let ab1 = \A.b.c
dump(ab1)

gives this diagnostic:

error: MyPlayground.playground:3:11: error: expression type 'WritableKeyPath<A, Int>' is ambiguous without more context
let ab1 = \A.b.c

That's really unhelpful. The issue here is that a ? is missing. It should be \A.b?.c.

@mdiep
Copy link
Contributor Author

mdiep commented Aug 15, 2017

It's not clear to me that \A.b.c means anything, so I'm left wondering if KeyPaths should even use ?.

@belkadan
Copy link
Contributor

cc @jckarter, @xedin

@LucianoPAlmeida
Copy link
Collaborator

On 2020-06-13 master snapshot I'm seeing

![](Screen Shot 2020-06-14 at 12.21.48.png)

@gregomni
Copy link
Collaborator

@LucianoPAlmeida - Sorry, I started looking at this because I hadn't noticed that you'd assigned it to yourself. The fix needs to deal with key path expressions specially to get the particular component involved. Something like this: <gregomni@b164ae8c7a30656d7b986aa1edfaf1f08b7c2f1c\>

@LucianoPAlmeida
Copy link
Collaborator

Ahh thank you, I had the PR opened right after the post, very similar except for the SourceLoc part, which I believe is an improvement. I'll adjust that and add you as a reviewer as well 🙂

@LucianoPAlmeida
Copy link
Collaborator

@mdiep This is fixed on master, can you please verify on the next available master snapshot and close? Thanks

@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
Projects
None yet
Development

No branches or pull requests

4 participants