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-11465] Ambiguity in expression which matches both dynamic member lookup and declaration from constrained extension #53865

Closed
xedin opened this issue Sep 12, 2019 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@xedin
Copy link
Member

xedin commented Sep 12, 2019

Previous ID SR-11465
Radar rdar://problem/55314724
Original Reporter @xedin
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @xedin
Priority Medium

md5: de8449f086382bed02c02efb5bdec874

Issue Description:

@dynamicMemberLookup public struct Tagged<Tag, RawValue> {
  public var rawValue: RawValue
  public init(rawValue: RawValue) {
    self.rawValue = rawValue
  }
  public subscript<Subject>(dynamicMember keyPath: KeyPath<RawValue, Subject>) -> Subject {
    rawValue[keyPath: keyPath]
  }
}

extension Tagged: Hashable, Equatable where RawValue: Hashable {
  public func hash(into hasher: inout Hasher) {
    hasher.combine(self.rawValue)
  }
}

func testHashable() {
  enum Tag { }
  Tagged<Tag, Int>(rawValue: 1).hashValue //ambiguous reference to member hashValue
}

I.e. theres ambiguity between the default implementation of hashValue inherited from Hashable and accessing the underlying rawValue.hashValue via the [dynamicMember:] subscript. The latter is still accessible via the subscript (i.e. Tagged<Tag,Int>(rawValue: 1)[dynamicMember: .hashValue]) but former is almost completely lost. The types exactly match up, and acessing via [keyPath:] subscript is impossible since creating the KeyPath runs into the same problem. as Hashable is not an option because of associated types.

Forum Thread: https://forums.swift.org/t/dynamicmemberlookup-introduces-ambiguity/28781

@xedin
Copy link
Member Author

xedin commented Sep 12, 2019

@swift-ci create

@xedin
Copy link
Member Author

xedin commented Sep 13, 2019

Fixed by #27146

@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

1 participant