Skip to content

Comparisons of structs with == lower suprisingly to === and documenation doesn't make it clear #51133

Open
@freemin7

Description

versioninfo()
Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, tigerlake)
  Threads: 1 on 8 virtual cores

installed via JuliaUp

using UUIDs

struct flower
    car::Vector{UUID}
    house::UUID
end

 uidv = [UUIDs.uuid4(), UUIDs.uuid4(), UUIDs.uuid4()]
 uid = UUIDs.uuid4()
 
 lettuce = flower(uidv, uid)


@assert typeof(lettuce) == typeof(eval( Meta.parse( string(flower(uidv, uid))))) ## passes
@assert lettuce.car == eval( Meta.parse( string(flower(uidv, uid)))).car ## passes
@assert typeof(lettuce.car) == typeof(eval( Meta.parse( string(flower(uidv, uid)))).car) ## passes
@assert lettuce.house == eval( Meta.parse( string(flower(uidv, uid)))).house ## passes
@assert typeof(lettuce.house) == typeof(eval( Meta.parse( string(flower(uidv, uid)))).house) ## passes
@assert fieldcount(flower) == 2
@assert string(lettuce) == string(eval( Meta.parse( string(flower(uidv, uid))))) ## passess

@assert hash(lettuce.house) == hash(eval( Meta.parse( string(flower(uidv, uid)))).house) ## passes
@assert hash(lettuce.car) == hash(eval( Meta.parse( string(flower(uidv, uid)))).car) ## passes
@assert flower(uidv, uid) == flower(uidv, uid)


@assert flower(uidv, uid) == eval(:(flower(uidv, uid)))


## So they should be identical in every way but
## both comparisons below fail
@assert lettuce == eval( Meta.parse( string(flower(uidv, uid)))) 
@assert hash(lettuce) == hash(eval( Meta.parse( string(flower(uidv, uid))))) 

Context: I discovered this problem using JSON3 where deserialisation/serialisation identities failed however could reproduce the issue in without those packages loaded. The same holds for uuid1. This is extremely cursed.

Some more testing yielded that:

cornflakes = string(flower(uidv, uid))
@assert cornflakes == string(flower(uidv, uid)) ## passes
soap = Meta.parse(cornflakes)
@assert soap == Meta.parse(cornflakes) ## passes

@assert eval(soap) == eval(soap) ## Fails

## this also fails
@assert eval(:(flower(UUID[UUID("c473d632-4815-11ee-047b-53ba6f201cba"), UUID("c473d644-4815-11ee-2bf5-01764c9f2b45"), UUID("c473d658-4815-11ee-361c-3d983a147777")], UUID("c4745718-4815-11ee-1ec9-fb22fba57306")))) == eval(:(flower(UUID[UUID("c473d632-4815-11ee-047b-53ba6f201cba"), UUID("c473d644-4815-11ee-2bf5-01764c9f2b45"), UUID("c473d658-4815-11ee-361c-3d983a147777")], UUID("c4745718-4815-11ee-1ec9-fb22fba57306"))))

## while those two pass
@assert eval(:(UUID[UUID("c473d632-4815-11ee-047b-53ba6f201cba"), UUID("c473d644-4815-11ee-2bf5-01764c9f2b45"), UUID("c473d658-4815-11ee-361c-3d983a147777")])) == eval(:(UUID[UUID("c473d632-4815-11ee-047b-53ba6f201cba"), UUID("c473d644-4815-11ee-2bf5-01764c9f2b45"), UUID("c473d658-4815-11ee-361c-3d983a147777")]))

@assert eval(:(UUID("c473d658-4815-11ee-361c-3d983a147777"))) == eval(:(UUID("c473d658-4815-11ee-361c-3d983a147777")))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    docsThis change adds or pertains to documentationequalityIssues relating to equality relations: ==, ===, isequal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions