Skip to content

Commit

Permalink
improve an error #160
Browse files Browse the repository at this point in the history
  • Loading branch information
jw3126 committed Jul 27, 2024
1 parent 4c297d1 commit be138a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/sugar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ function parse_obj_optics(ex)
optic = :(Base.Fix1($f, $(esc(args[1]))))
end
else
for bad_symbol in [Symbol("&&"), Symbol("||")]
if isexpr(ex, bad_symbol)
msg = """The $bad_symbol operator is not supported inside optics.
See also https://github.com/JuliaObjects/Accessors.jl/issues/160."
"""
error(msg)
end
end
obj = esc(ex)
return obj, ()
end
Expand Down
5 changes: 5 additions & 0 deletions test/test_optics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,9 @@ end
end
end

@testset "Cannot parse optic _ && true #160" begin
res = @test_throws "The && operator is not supported inside optics." Accessors.opticmacro(identity, :(_ && true))
res = @test_throws "The || operator is not supported inside optics." Accessors.opticmacro(identity, :(f(g(_) || a(x))))
end

end#module

0 comments on commit be138a0

Please sign in to comment.