diff --git a/Project.toml b/Project.toml index 23ca1947..f2aa9cd5 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Accessors" uuid = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" authors = ["Takafumi Arakaki ", "Jan Weidner and contributors"] -version = "0.1.37" +version = "0.1.38" [deps] CompositionsBase = "a33af91c-f02d-484b-be07-31d278c5ca2b" diff --git a/src/sugar.jl b/src/sugar.jl index 640636b3..dca875e7 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 (:&&, :||) + 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..4813a0e3 100644 --- a/test/test_optics.jl +++ b/test/test_optics.jl @@ -121,4 +121,11 @@ end end end +@testset "Cannot parse optic _ && true #160" begin + res = @test_throws Exception Accessors.opticmacro(identity, :(_ && true)) + @test occursin("The && operator is not supported inside optics.", res.value.msg) + res = @test_throws Exception Accessors.opticmacro(identity, :(f(g(_) || a(x)))) + @test occursin("The || operator is not supported inside optics.", res.value.msg) +end + end#module