beacon-biosignals / Legolas.jl

Tables.jl-friendly mechanisms for constructing, reading, writing, and validating Arrow tables against extensible, versioned, user-specified schemas.
Other
24 stars 2 forks source link

`==` semantics don't match NamedTuple's in presence of missing field #101

Closed ericphanson closed 1 year ago

ericphanson commented 1 year ago
julia> using Legolas

julia> using Legolas: @schema, @version

julia> @schema "example.foo" Foo

julia> @version FooV1 begin
            a::Union{Missing, Int}
            b::Union{Missing, Int}
        end

julia> x = (; a = missing, b = 1)
(a = missing, b = 1)

julia> y = (; a = missing, b = 2)
(a = missing, b = 2)

julia> x == y
false

julia> FooV1(x) == FooV1(y)
ERROR: TypeError: non-boolean (Missing) used in boolean context
Stacktrace:
 [1] ==(a::FooV1, b::FooV1)
   @ Main ~/.julia/packages/Legolas/0cASP/src/schemas.jl:668
 [2] top-level scope
   @ REPL[11]:1
 [3] top-level scope
   @ ~/.julia/juliaup/julia-1.9.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.9/REPL/src/REPL.jl:1416

due to the implementation in https://github.com/beacon-biosignals/Legolas.jl/blob/0d9ec276241dfe1dc46aae64cad4e3d5394c7fb9/src/schemas.jl#L664. We should use something like https://github.com/JuliaServices/AutoHashEquals.jl/pull/45/files#diff-338e197a5b351ab9a74086bcc5d606d7c05b969f9d4b4b5bcf67b8f7083ec852R321-R355 which matches Base's https://github.com/JuliaLang/julia/blob/96e5b62e95f79a64ab296001dd8cf748c63af806/base/tuple.jl#L482-L514.