Skip to content

AnyHashable type-erasing behaves differently on Linux #77508

Open
@tomsci

Description

@tomsci

Description

On the linux build of Swift, AnyHashable does not appear to have the type-erasing semantics that it does on macOS and iOS. On those platforms, any type of integer converted to an AnyHashable can then be converted to any other type of integer (providing it fits), whereas on linux, you can only convert it back to the original type.

Reproduction

let i: Int32 = 1
let a = i as AnyHashable
let oi = a as? Int8 // This conversion succeeds on macOS/iOS, fails on linux

Expected behavior

Expected the as? Int8 to succeed and return Optional<Int8>(1) on all platforms. It only succeeds on macOS and iOS, and returns nil on linux.

Environment

Swift version 5.10.1 (swift-5.10.1-RELEASE)
Ubuntu 22.04.5 LTS

Additional information

Tested using the following github actions job: tomsci/LuaSwift#7
The issue was found during the development of tomsci/LuaSwift#6 which necessitated a lot of additional code to compensate for the difference in behaviour of AnyHashable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FoundationLinuxPlatform: LinuxbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.castingFeature: explicit casting (is, as, as? and as!)transfer candidateThe issue may belong in another repository

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions