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-5973] Abbreviated key path subscript notation is ambiguous #48532

Closed
stephencelis opened this issue Sep 23, 2017 · 4 comments
Closed

[SR-5973] Abbreviated key path subscript notation is ambiguous #48532

stephencelis opened this issue Sep 23, 2017 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@stephencelis
Copy link
Contributor

Previous ID SR-5973
Radar rdar://problem/37749554
Original Reporter @stephencelis
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 9, Swift Development Snapshot (9/22/2017)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 3e38e7bce2da1329ef063d4a9ae3c2cb

duplicates:

  • SR-5865 Key path expression is "ambiguous without more context"

Issue Description:

KeyPath subscripts are nice! Just came across a small gotcha: abbreviated syntax doesn't seem to compile.

let arr = [1, 2, 3]

arr[keyPath: \[Int].[0]]
arr[keyPath: \Array.[0]]
// both return 1

arr[keyPath: \.[0]]
// error: type of expression is ambiguous without more context

(Also still seeing the "Key path support for subscript components is not implemented" diagnostic popping up in Xcode, but things build and work just fine, so maybe this is an Xcode bug/artifact.)

@belkadan
Copy link
Contributor

@jckarter, any ideas? My understanding is that the first line should actually be illegal and the last one should be unambiguous.

@stephencelis
Copy link
Contributor Author

@belkadan Oops, I had a typo. Should've copy-pasted. Updated in the description, but that should have been [Int].[0].

@stephencelis
Copy link
Contributor Author

Still seeing this. It only seems to be ambiguous when passed to the key path subscript proper. Key paths are awesome and though the abbreviation is mostly helpful outside the direct subscript syntax, it'd be awesome to be consistent here for teaching purposes 🙂

@belkadan
Copy link
Contributor

@swift-ci create

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

No branches or pull requests

2 participants