Inconsistency in multi-line statements

Why is this interpreted as one multi-line statement and successfully compiles

val x = true
    || false
    || true

But the following fails to compile

val x2 = true
    or false
    or true

val x3 = 1
    * 2
    * 3

There’s additional confusion with the following

val x4 = 1
    + 2
    + 3

This compiles and may look like you’re adding three numbers if you’re used to the || syntax with booleans, but it’s interpreted as 3 distinct statements and compiles because + works as a unary operator. The value of x4 will be 1 not 6.

1 Like