diff --git a/src/sugar.jl b/src/sugar.jl index cff269d6..bbf645c2 100644 --- a/src/sugar.jl +++ b/src/sugar.jl @@ -248,6 +248,10 @@ function parse_obj_optics(ex) obj, frontoptic = parse_obj_optics(args[2]) optic = :(Base.Fix1($f, $(esc(args[1])))) end + elseif @capture(ex, s_Symbol) + # the symbol can be wrapped in quote ... end, need to unwrap for reliable handling downstream + obj = esc(s) + return obj, () else obj = esc(ex) return obj, () diff --git a/test/test_core.jl b/test/test_core.jl index ede62884..c0b29ee2 100644 --- a/test/test_core.jl +++ b/test/test_core.jl @@ -602,6 +602,7 @@ struct MyStruct end "Documentation for my_x" @accessor my_x(v) = v.x +@accessor my_identity(v) = v @accessor Base.:(+)(s::MyStruct) = 5 - s.x.a @accessor Base.Int(s::MyStruct) = s.x[1] @accessor Base.Float64(s::MyStruct) = s.x[2] @@ -617,6 +618,7 @@ import REPL @test (@set my_x(s) = 456) === MyStruct(456) @test (@set +s = 456) === MyStruct((a=5-456,)) test_getset_laws(my_x, s, 456, "1") + test_getset_laws(my_identity, 123, 456, "1") test_getset_laws(+, s, 456, 1.0) s = MyStruct((1, 2.0))