As I said, there’s a difference between expressions (paranthesis) and functions (braces).
if(true, x = x + 1, { y = y + 1 })
Here the first argument is an expression and the second argument is a function. The braces are not optional!
You can actually see it in the byte code:
- push
true
- evaluate the expression
x = x + 1
and push the result on the stack = ARG1 - push the function
{ y = y + 1 }
on the stack (don’t evaluate it!) = ARG2 - call the
if
method ontrue
with ARG1 and ARG2 as arguments -
if
will evaluate ARG1 (does nothing) and return it. ARG2 is discarded (= short circuiting).
Again, the if
method itself always short-circuits.