diff --git a/src/sugar.jl b/src/sugar.jl index 640636b3..77b0c47b 100644 --- a/src/sugar.jl +++ b/src/sugar.jl @@ -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 diff --git a/test/test_optics.jl b/test/test_optics.jl index 57b5bd61..9a3651ad 100644 --- a/test/test_optics.jl +++ b/test/test_optics.jl @@ -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