https://go.dev/play/p/oG6FEe-1yB2 demonstrates a valid (I think) input to ParseExpr that causes it to fail:

(a && b                 // Error: expected ')', found newline
)

I guess it is being turned into a semicolon. But that's a bug, isn't it?

(This came up in the context of x/telemetry/cmd/stacks.)

@griesemer

Comment From: gabyhelp

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: adonovan

Hmm... the spec says:

Semicolons The formal syntax uses semicolons ";" as terminators in a number of productions. Go programs may omit most of these semicolons using the following two rules:

When the input is broken into tokens, a semicolon is automatically inserted into the token stream immediately after a line's final token if that token is - an identifier ...

so perhaps this is working as intended. Never mind.

Comment From: griesemer

Yes, I believe this is working as intended (and the related issue was fixed correctly, I believe).

I suppose we could turn off automatic semicolon insertion for expressions parsing, which might make some sense, but I point out that an expression may contain statements...

unsafe.Sizeof(func() {
    _ = 42
})

so we probably shouldn't do that.