Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
  • Loading branch information
sunxd3 and devmotion committed Apr 1, 2024
1 parent dca1020 commit 76ace06
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/varname.jl
Expand Up @@ -673,10 +673,9 @@ end
# Accessors doesn't have the same support for interpolation
# so this function is copied and altered from `Setfield._parse_obj_lens`
function _parse_obj_optics(ex)
if ex isa Expr && ex.head == :$
@assert length(ex.args) == 1
if Meta.isexpr(ex, :$, 1)
return esc(:_), (esc(ex.args[1]),)
elseif Meta.isexpr(ex, :ref)
elseif Meta.isexpr(ex, :ref) && !isempty(ex.args)
front, indices... = ex.args
obj, frontoptics = _parse_obj_optics(front)
if any(Accessors.need_dynamic_optic, indices)
Expand All @@ -689,13 +688,13 @@ function _parse_obj_optics(ex)
index = esc(Expr(:tuple, indices...))
optics = :($(Accessors.IndexLens)($index))
end
elseif Meta.isexpr(ex, :.)
elseif Meta.isexpr(ex, :., 2)
front = ex.args[1]
property = ex.args[2].value # ex.args[2] is a QuoteNode
obj, frontoptics = _parse_obj_optics(front)
if property isa Union{Symbol,String}
optics = :($(Accessors.PropertyLens){$(QuoteNode(property))}())
elseif property isa Expr && property.head == :$
elseif Meta.isexpr(property, :$, 1)
optics = :($(Accessors.PropertyLens){$(esc(property.args[1]))}())
else
throw(ArgumentError(
Expand Down
1 change: 0 additions & 1 deletion test/varname.jl
Expand Up @@ -89,7 +89,6 @@ end
@test collect(get(B, @varname(B[1, :], true))) == collect(get(B, @varname(B[1, -4:5])))

end

@testset "type stability" begin
@inferred VarName{:a}()
@inferred VarName{:a}(IndexLens(1))
Expand Down

0 comments on commit 76ace06

Please sign in to comment.