Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Cannot parse optic _ && true #160 #161

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Accessors"
uuid = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
authors = ["Takafumi Arakaki <[email protected]>", "Jan Weidner <[email protected]> and contributors"]
version = "0.1.37"
version = "0.1.38"

[deps]
CompositionsBase = "a33af91c-f02d-484b-be07-31d278c5ca2b"
Expand Down
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 (:&&, :||)
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
7 changes: 7 additions & 0 deletions test/test_optics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading