Skip to content

Commit 516efd7

Browse files
committed
fix trivial @Accessor functions
1 parent 11e9dc4 commit 516efd7

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/sugar.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ function parse_obj_optics(ex)
248248
obj, frontoptic = parse_obj_optics(args[2])
249249
optic = :(Base.Fix1($f, $(esc(args[1]))))
250250
end
251+
elseif @capture(ex, s_Symbol)
252+
# the symbol can be wrapped in quote ... end, need to unwrap for reliable handling downstream
253+
obj = esc(s)
254+
return obj, ()
251255
else
252256
obj = esc(ex)
253257
return obj, ()

test/test_core.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ struct MyStruct
598598
end
599599
"Documentation for my_x"
600600
@accessor my_x(v) = v.x
601+
@accessor my_identity(v) = v
601602
@accessor Base.:(+)(s::MyStruct) = 5 - s.x.a
602603
@accessor Base.Int(s::MyStruct) = s.x[1]
603604
@accessor Base.Float64(s::MyStruct) = s.x[2]
@@ -613,6 +614,7 @@ import REPL
613614
@test (@set my_x(s) = 456) === MyStruct(456)
614615
@test (@set +s = 456) === MyStruct((a=5-456,))
615616
test_getset_laws(my_x, s, 456, "1")
617+
test_getset_laws(my_identity, 123, 456, "1")
616618
test_getset_laws(+, s, 456, 1.0)
617619

618620
s = MyStruct((1, 2.0))

0 commit comments

Comments
 (0)