Skip to content

[SR-12092] AnyHashable instances with unrelated base types compare equal #54528

@NevinBR

Description

@NevinBR
Previous ID SR-12092
Radar rdar://problem/58999133
Original Reporter @NevinBR
Type Bug
Status Resolved
Resolution Done
Environment

• Swift 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
• MacOS 10.14.6 (18G103)

I observe the same results in both:
• Xcode 11.3.1 playground for MacOS
• Swift REPL in Terminal

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

md5: 977913cfdf8c4746de5a59c4a30a3555

Issue Description:

When values representing the same integer are stored as different types (whether integer or floating-point) then wrapped in AnyHashable, the resulting AnyHashable instances compare equal even though the underlying base types are different:

let a = AnyHashable(1)
let b = AnyHashable(1.0)
let c = AnyHashable(1 as UInt8)
(a == b, a == c, b == c)    // (true, true, true)
type(of: a.base) == type(of: b.base)  // false
type(of: a.base) == type(of: c.base)  // false
type(of: b.base) == type(of: c.base)  // false

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.standard libraryArea: Standard library umbrella

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions