# Weird syntax error

**URL:** <https://discourse.julialang.org/t/weird-syntax-error/89591>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 1, 2022, 3:16am UTC](https://discourse.julialang.org/t/weird-syntax-error/89591 "2022-11-01T03:16:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![pjssilva](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pjssilva/32/4238_2.png) [@pjssilva](https://discourse.julialang.org/u/pjssilva)\
**Post date:** [November 1, 2022, 3:16am UTC](https://discourse.julialang.org/t/weird-syntax-error/89591/1 "2022-11-01T03:16:34Z")

</div>

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?

```julia
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.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [November 1, 2022, 3:32am UTC](https://discourse.julialang.org/t/weird-syntax-error/89591/2 "2022-11-01T03:32:58Z")

</div>

This can be reduced to

```julia
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.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [November 1, 2022, 3:40am UTC](https://discourse.julialang.org/t/weird-syntax-error/89591/3 "2022-11-01T03:40:43Z")

</div>

it has something to do with anonymous function

```julia
julia> if true
       elseif (0 == 0) || (any(iszero, [1]))
       end

```

works

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [November 1, 2022, 3:54am UTC](https://discourse.julialang.org/t/weird-syntax-error/89591/4 "2022-11-01T03:54:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pjssilva](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pjssilva/32/4238_2.png) [@pjssilva](https://discourse.julialang.org/u/pjssilva)\
**Post date:** [November 1, 2022, 4:04am UTC](https://discourse.julialang.org/t/weird-syntax-error/89591/5 "2022-11-01T04:04:23Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [November 1, 2022, 5:00am UTC](https://discourse.julialang.org/t/weird-syntax-error/89591/6 "2022-11-01T05:00:25Z")

</div>

seems like what’s necessary is:

1. at least one anonymous function definition, and
2. at least one short-circuiting operator `&&` or `||`, inside
3. `elseif`

Causes syntax errors:

A.

```julia
if false
elseif false || (()->true)()
end

```

B.

```julia
if false
elseif false && (()->true)()
end

```

C.

```julia
if false
elseif false || false || (()->true)()
end

```

D.

```julia
if false
elseif (()->true)() || false
end

```

E.

```julia
if rand((false, true))
elseif rand((false, true)) || (()->true)()
end

```

F.

```julia
if true
elseif true || x->x
end

```

G.

```julia
if false
elseif false
elseif false || x->x
end

```

H.

```julia
if false
elseif (x->x) || x->x
end

```

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [November 1, 2022, 5:05am UTC](https://discourse.julialang.org/t/weird-syntax-error/89591/7 "2022-11-01T05:05:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [November 1, 2022, 1:44pm UTC](https://discourse.julialang.org/t/weird-syntax-error/89591/8 "2022-11-01T13:44:46Z")

</div>

Fascinating. It works for me in 1.6.2:

```julia
  | | |_| | | | (_| | | 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

```

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [November 1, 2022, 2:05pm UTC](https://discourse.julialang.org/t/weird-syntax-error/89591/9 "2022-11-01T14:05:42Z")

</div>

I hope you don’t mind that I stole your thunder, but I opened an issue for this bug here [`elseif` raises an error when used with both short-circuiting evaluation and anonymous function · Issue #47410 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/47410)

---

<div class="post-metadata">

**Author:** ![pjssilva](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pjssilva/32/4238_2.png) [@pjssilva](https://discourse.julialang.org/u/pjssilva)\
**Post date:** [November 1, 2022, 2:16pm UTC](https://discourse.julialang.org/t/weird-syntax-error/89591/10 "2022-11-01T14:16:18Z")

</div>

Thanks @adienes. I have just subscribed to the bug report. Glad that my eyeballs were of some use.

---

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [November 16, 2022, 5:58am UTC](https://discourse.julialang.org/t/weird-syntax-error/89591/11 "2022-11-16T05:58:12Z")

</div>

This is fixed now by [fix #47410, syntax error with anonfn inside `elseif` and short-circuit op by JeffBezanson · Pull Request #47499 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/47499). Thanks for the reports and analysis!
