The code below fails with a syntax error that seems related to the creation of the anonymous function. I don’t see why it is a syntax error. Can anyone explain it?
let
if 0 == 0
1
elseif 0 == 0 || !all(x -> true, [1])
2
else
3
end
end
Obs: The code does not make sense. It is a minimal version of an error I am finding in another code.
1 Like
This can be reduced to
if false
elseif (true || all(x -> true, [1]))
println("hi")
end
I tried changing some stuff like parentheses and !
around. To my eyes it seems to be a bug with the interaction of elseif
, ||
, and the all
function.
1 Like
jling
November 1, 2022, 3:40am
3
it has something to do with anonymous function
julia> if true
elseif (0 == 0) || (any(iszero, [1]))
end
works
1 Like
rdeits
November 1, 2022, 3:54am
4
The minimal example from @adienes
works in Julia 1.6 but fails in 1.7, so it’s probably a bug in Julia itself. Want to open an issue?
@rdeits , I have just downloaded the last Julia 1.6 (1.6.7) and tried @adienes minimal version there. It also fails. Which 1.6.X did you test?
seems like what’s necessary is:
at least one anonymous function definition, and
at least one short-circuiting operator &&
or ||
, inside
elseif
Causes syntax errors:
A.
if false
elseif false || (()->true)()
end
B.
if false
elseif false && (()->true)()
end
C.
if false
elseif false || false || (()->true)()
end
D.
if false
elseif (()->true)() || false
end
E.
if rand((false, true))
elseif rand((false, true)) || (()->true)()
end
F.
if true
elseif true || x->x
end
G.
if false
elseif false
elseif false || x->x
end
H.
if false
elseif (x->x) || x->x
end
If you pass the whole minimal example block of code into code_lowered
, it correctly prints "hi"
. The error persists when using JuliaSyntax.jl
btw.
rdeits
November 1, 2022, 1:44pm
8
Fascinating. It works for me in 1.6.2:
| | |_| | | | (_| | | Version 1.6.2 (2021-07-14)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> if false
elseif (true || all(x -> true, [1]))
println("hi")
end
hi
Thanks @adienes . I have just subscribed to the bug report. Glad that my eyeballs were of some use.
3 Likes
jameson
November 16, 2022, 5:58am
11
1 Like