Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ericphanson opened this issue Aug 20, 2023 · 0 comments · Fixed by #103
Closed

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

ericphanson opened this issue Aug 20, 2023 · 0 comments · Fixed by #103

Comments

@ericphanson
Copy link
Member

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

equal_rhs_statement = foldr((x, y) -> :($x && $y), (:(a.$f == b.$f) for f in keys(record_fields)))
. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant