Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix trivial @accessor functions #187

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/sugar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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, ()
Expand Down
2 changes: 2 additions & 0 deletions test/test_core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,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]
Expand All @@ -613,6 +614,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))
Expand Down
Loading