Expression parsing ambiguity

Hi! Recently I ran into a bit of behaviour which I find rather odd, because it feels like it could be a source of very hard to track bugs. However, I’m not sure whether this is intentional, or a bug, hence I want to ask here first, before submitting a bug report. Compare these three assignments:

val b = true
            && false
val p = 3
            + 4
val t = 3
            * 4

The interesting thing is, that the value of variable b will be false (the whole expression is parsed correctly), value of p will be 3 (because + 4 is parsed as application of unary +, instead of infix binary +). Finally, t won’t even compile, because there is no unary * and apparently, * doesn’t get the same treatment as && does.

Is this intentional? Isn’t there a way to make this more uniform? In Java, everything works as expected due to semicolons.

1 Like

I can’t speak for JetBrains but I would say this is not intentional. I am pretty sure that the behavior of the first case is intentional as it is an exception to the rule, that the end of a line ends an expression.
Another exception to this rule is member access which can also be done on a new line


I think this warrants a bug report :slight_smile:

And even if it is intentional (which I don’t believe) it is still an undocumented feature as far as I know.