JuliaServices / AutoHashEquals.jl

A Julia macro to add == and hash() to composite types.
Other
58 stars 12 forks source link

use `getfield` instead of `getproperty` #20

Closed goretkin closed 1 year ago

goretkin commented 3 years ago

The macros generate code that access fields like x.field, e.g.:

https://github.com/andrewcooke/AutoHashEquals.jl/blob/f643bdd354ffea0f3f7df3c23c8a965768e9ef0c/src/AutoHashEquals.jl#L31

but I think it should be replaced with getfield(x, :field), since some types may overload getproperty. Here is an obnoxious example:

julia> @auto_hash_equals struct Foo{T}
       _::T
       end

julia> ==(Foo(1), Foo(1))
true

julia> Base.getproperty(x::Foo, f::Symbol) = rand() # horrible but not "illegal"

julia> ==(Foo(1), Foo(1))
false
gafter commented 1 year ago

Current implementation uses getfield.