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

@auto_hash_equals ignores fields declared in begin...end #29

Open
gafter opened this issue Mar 21, 2023 · 1 comment
Open

@auto_hash_equals ignores fields declared in begin...end #29

gafter opened this issue Mar 21, 2023 · 1 comment

Comments

@gafter
Copy link
Member

gafter commented Mar 21, 2023

I don't know why anyone would do this, but it is legal in Julia (at least, the compiler accepts it) and it breaks @auto_hash_equals

module In0

using AutoHashEquals

@auto_hash_equals struct Q
    x::Int
    begin
    y::Int
    end
end

println(hash(Q(1, 2)))
println(hash(Q(1, 3)))
println(Q(1, 2) == Q(1, 3))

end

These two differently-valued instances of Q are treated as equal to each other.

@iamed2
Copy link
Collaborator

iamed2 commented Mar 21, 2023

I think the solution for this would be something like https://github.com/FluxML/MacroTools.jl/blob/d1937f95a7e5c82f9cc3b5a4f8a2b33fdb32f884/src/utils.jl#L454-L470 as a preprocessor. I think something like that would normally belong in ExprTools.jl but I think people are also happy that this package currently has no dependencies and it's probably fine to replicate that code in this package for this purpose specifically, if someone ends up needing it.

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

No branches or pull requests

2 participants