You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update == and isequal semantics to match NamedTuple's (#45)
Specifically:
- Define `==` in terms of `==` of members, properly handing `missing`.
- Define `isequal` in terms of `isequal` of members.
- Add an option `compat1=true` for clients who prefer the old behavior.
- This code tickles a bug in Julia that apparently is fixed in 1.8, so that is the new min version.
- Bump version to `2.0.0`
Co-authored-by: Neal Gafter <[email protected]>
We do not take the type arguments of a generic type into account for either`hash` or `==` unless `typearg=true` is specified (see below). So a `Box{Int}(1)` will test equal to a `Box{Any}(1)`.
31
+
We do not take the type arguments of a generic type into account for `isequal`,`hash`, or `==` unless `typearg=true` is specified (see below). So by default, a `Box{Int}(1)` will test equal to a `Box{Any}(1)`.
# Returns `false` if any two fields compare as false; otherwise, `missing` if at least
119
+
# one comparison is missing. Otherwise `true`.
120
+
# This matches the semantics of `==` for Tuple's and NamedTuple's.
121
+
function Base.:(==)(a::Foo, b::Foo)
122
+
found_missing =false
123
+
cmp = a.a == b.a
124
+
cmp ===false&&returnfalse
125
+
ifismissing(cmp)
126
+
found_missing =true
127
+
end
128
+
cmp = a.b == b.b
129
+
cmp ===false&&returnfalse
130
+
ifismissing(cmp)
131
+
found_missing =true
132
+
end
133
+
found_missing &&returnmissing
134
+
returntrue
135
+
end
112
136
```
113
137
114
138
## Specifying whether or not type arguments should be significant
115
139
116
140
You can specify that type arguments should be significant for the purposes of computing the hash function and checking equality by adding the keyword parameter `typearg=true`. By default they are not significant. You can specify the default (they are not significant) with `typearg=false`:
117
141
118
-
```julia-repl
142
+
```julia
119
143
julia>@auto_hash_equalsstruct Box1{T}
120
144
x::T
121
145
end
@@ -161,3 +185,32 @@ If `typearg=true`, then `e(t)` is used as the type seed, where `t` is the type o
161
185
162
186
Note that the value of `typeseed` is expected to be a `UInt` value when `typearg=false` (or `typearg` is not specified),
163
187
but a function that takes a type as its argument when `typearg=true`.
188
+
189
+
## Compatibility mode
190
+
191
+
In versions `v"1.0"` and earlier of `AutoHashEquals`, we produced a specialization of `Base.==`, implemented using `Base.isequal`.
192
+
This was not correct.
193
+
See https://docs.julialang.org/en/v1/base/base/#Base.isequal and https://docs.julialang.org/en/v1/base/math/#Base.:==.
194
+
More correct would be to define `==` by using `==` on the members, and to define `isequal` by using `isequal` on the members.
195
+
In version `v"2.0"` we provide a correct implementation, thanks to @ericphanson.
196
+
197
+
To get the same behavior as `v"1.0"` of this package, in which `==` is implemented based on `isequal`,
0 commit comments