From be138a0c38bcb81e54c00e801f1b13816daa933e Mon Sep 17 00:00:00 2001 From: Jan Weidner Date: Sat, 27 Jul 2024 12:08:36 +0200 Subject: [PATCH 1/4] improve an error #160 --- src/sugar.jl | 8 ++++++++ test/test_optics.jl | 5 +++++ 2 files changed, 13 insertions(+) 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 From 4e5b99f97dc248fbf74f11c46ba30c88f7f8503e Mon Sep 17 00:00:00 2001 From: Jan Weidner Date: Sat, 27 Jul 2024 12:08:50 +0200 Subject: [PATCH 2/4] bump --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From 3f0c831ff9443fa6cdedd206f1e542e6d160e74f Mon Sep 17 00:00:00 2001 From: Jan Weidner Date: Sat, 27 Jul 2024 12:32:26 +0200 Subject: [PATCH 3/4] make test backward compat --- test/test_optics.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test_optics.jl b/test/test_optics.jl index 9a3651ad..4813a0e3 100644 --- a/test/test_optics.jl +++ b/test/test_optics.jl @@ -122,8 +122,10 @@ 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)))) + 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 From 530fa6d133f8ef40df80ba97004fb75228c26f5d Mon Sep 17 00:00:00 2001 From: Jan Weidner Date: Sun, 28 Jul 2024 08:27:27 +0200 Subject: [PATCH 4/4] cleanup --- src/sugar.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sugar.jl b/src/sugar.jl index 77b0c47b..dca875e7 100644 --- a/src/sugar.jl +++ b/src/sugar.jl @@ -249,7 +249,7 @@ function parse_obj_optics(ex) optic = :(Base.Fix1($f, $(esc(args[1])))) end else - for bad_symbol in [Symbol("&&"), Symbol("||")] + 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."