You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@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.
Additional Detail from JIRA
md5: de8449f086382bed02c02efb5bdec874
Issue Description:
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
The text was updated successfully, but these errors were encountered: