Skip to content

AnyHashable behaves differently on Linux #82819

Open
@flymedllva

Description

@flymedllva

Description

AnyHashable in Swift on Linux behaves differently

Reproduction

Case 1

import Foundation

var d = """
    {"test":{"test":1}}
    """.data(using: .utf8)!

public typealias JSONValue = any Sendable & Hashable
public typealias JSONObject = [String: JSONValue]

let a = try JSONSerialization.jsonObject(with: d, options: [])
let b = a as! Dictionary<String, Any> as (JSONValue)
let c = b as? AnyHashable as? JSONObject

print(c)

Not Linux:

Optional(["test": AnyHashable([AnyHashable("test"): AnyHashable(1)])])

Linux:

nil

Case 2

import Foundation

var d = """
    {"test":{"test":1}}
    """.data(using: .utf8)!

public typealias JSONValue = any Sendable & Hashable
public typealias JSONObject = [String: JSONValue]

let a = try JSONSerialization.jsonObject(with: d, options: [])
let b = a as! Dictionary<String, Any> as (JSONValue)
let c = b as? AnyHashable

print(c)

Not Linux:

Optional(AnyHashable([AnyHashable("test"): AnyHashable([AnyHashable("test"): AnyHashable(1)])]))

Linux:

Optional(AnyHashable({
    test =     {
        test = 1;
    };
}))

Expected behavior

Behavior as on the main platforms (iOS/macOS/etc), otherwise the result of code work is different

Environment

swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions