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-12387] Self key path literal function expression failure #54824

Closed
stephencelis opened this issue Mar 20, 2020 · 3 comments
Closed

[SR-12387] Self key path literal function expression failure #54824

stephencelis opened this issue Mar 20, 2020 · 3 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-12387
Radar rdar://problem/60832831
Original Reporter @stephencelis
Type Bug
Environment

Swift 5.2

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

md5: c7e6a520962d91be27623d1bf56a50ce

Issue Description:

The following code fails to compile in a playground:

struct Identified<A>: Identifiable {
  var value: A
  var id: AnyHashable  init<B: Hashable>(_ value: A, by hashable: (A) -> B) {
    self.value = value
    self.id = hashable(value)
  }

//  init<B: Hashable>(_ value: A, by hashable: KeyPath<A, B>) {
//    self.value = value
//    self.id = value[keyPath: hashable]
//  }
}

Identified(1, by: \.self)

cannot convert value of type 'WritableKeyPath<_, _>' to expected argument type '(Int) -> B'

The commented-out overload seems to be required. When commented-in, the code behaves as expected.

In general, the "self" key path doesn't seem to work in expected situations. For example:

[Optional(1), 2, 3].compactMap(\.self)

error: type of expression is ambiguous without more context

@beccadax
Copy link
Contributor

@swift-ci create

@mattyoung
Copy link

Duplicate of https://bugs.swift.org/browse/SR-12897

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@xedin
Copy link
Member

xedin commented Dec 8, 2023

I think this has been fixed by combination of the following PRs - #69742, #69742. All of the expressions mentioned in the description now type-check.

Please use the latest main compiler snapshot to verify and re-open.

@xedin xedin closed this as completed Dec 8, 2023
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

4 participants