Skip to content

Commit bff69d5

Browse files
authored
Merge pull request #166 from phipsgabler/phg/equality
Remove type parameters from == methods of IndexLens and CompositeLens
2 parents d8938be + 9243ef8 commit bff69d5

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Setfield"
22
uuid = "efcf1570-3423-57d1-acb7-fd33fddbac46"
3-
version = "0.8.0"
3+
version = "0.8.1"
44

55
[deps]
66
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"

src/lens.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ struct ComposedLens{LO, LI} <: Lens
127127
inner::LI
128128
end
129129

130-
function ==(l1::ComposedLens{LO, LI}, l2::ComposedLens{LO, LI}) where {LO, LI}
130+
function ==(l1::ComposedLens, l2::ComposedLens)
131131
return l1.outer == l2.outer && l1.inner == l2.inner
132132
end
133133

@@ -193,7 +193,7 @@ struct IndexLens{I <: Tuple} <: Lens
193193
indices::I
194194
end
195195

196-
==(l1::IndexLens{I}, l2::IndexLens{I}) where {I} = l1.indices == l2.indices
196+
==(l1::IndexLens, l2::IndexLens) = l1.indices == l2.indices
197197

198198
const SALT_INDEXLENS = make_salt(0x8b4fd6f97c6aeed6)
199199
hash(l::IndexLens, h::UInt) = hash(l.indices, SALT_INDEXLENS + h)

test/test_core.jl

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ end
209209
# singletons (identity and property lens) are egal
210210
for (l1, l2) [
211211
@lens(_) => @lens(_),
212-
@lens(_.a) => @lens(_.a)
212+
@lens(_.a) => @lens(_.a),
213213
]
214214
@test l1 === l2
215215
@test l1 == l2
@@ -218,23 +218,41 @@ end
218218

219219
# composite and index lenses are structurally equal
220220
for (l1, l2) [
221-
@lens(_[1]) => @lens(_[1])
222-
@lens(_.a[2]) => @lens(_.a[2])
223-
@lens(_.a.b[3]) => @lens(_.a.b[3])
221+
@lens(_[1]) => @lens(_[1]),
222+
@lens(_.a[2]) => @lens(_.a[2]),
223+
@lens(_.a.b[3]) => @lens(_.a.b[3]),
224+
@lens(_[1:10]) => @lens(_[1:10]),
225+
@lens(_.a[2:20]) => @lens(_.a[2:20]),
226+
@lens(_.a.b[3:30]) => @lens(_.a.b[3:30]),
224227
]
225228
@test l1 == l2
226229
@test hash(l1) == hash(l2)
227230
end
228231

229232
# inequality
230233
for (l1, l2) [
231-
@lens(_[1]) => @lens(_[2])
232-
@lens(_.a[1]) => @lens(_.a[2])
233-
@lens(_.a[1]) => @lens(_.b[1])
234+
@lens(_[1]) => @lens(_[2]),
235+
@lens(_.a[1]) => @lens(_.a[2]),
236+
@lens(_.a[1]) => @lens(_.b[1]),
237+
@lens(_[1:10]) => @lens(_[2:20]),
238+
@lens(_.a[1:10]) => @lens(_.a[2:20]),
239+
@lens(_.a[1:10]) => @lens(_.b[1:10]),
234240
]
235241
@test l1 != l2
236242
end
237243

244+
# equality with non-equal range types (#165)
245+
for (l1, l2) [
246+
@lens(_[1:10]) => @lens(_[Base.OneTo(10)]),
247+
@lens(_.a[1:10]) => @lens(_.a[Base.OneTo(10)]),
248+
@lens(_.a.b[1:10]) => @lens(_.a.b[Base.OneTo(10)]),
249+
@lens(_.a[Base.StepRange(1, 1, 5)].b[1:10]) => @lens(_.a[1:5].b[Base.OneTo(10)]),
250+
@lens(_.a.b[1:3]) => @lens(_.a.b[[1, 2, 3]]),
251+
]
252+
@test l1 == l2
253+
@test hash(l1) == hash(l2)
254+
end
255+
238256
# Hash property: equality implies equal hashes, or in other terms:
239257
# lenses either have equal hashes or are unequal
240258
# Because collisions can occur theoretically (though unlikely), this is a property test,

0 commit comments

Comments
 (0)