You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
I'm running this example on the Go Playground. Since the result is a syntax error, I don't believe operating system and processor architecture are relevant. (However, I can provide information about my machine if needed).
I believe this is happening because the '{' after the type name is being interpreted as the beginning of the BLOCK.
I've recently spent some time studying the code for the Go parser. At first glance it seems like it would be difficult to distinguish between the beginning of a block and a composite literal expression without arbitrary lookahead. One possible solution is to simply add a note to the spec indicating that this syntax is not allowed.
It is also possible that the Go Spec contains many such edge cases, and noting all of them in a public document is impractical. I just wanted to bring some attention to this particular case to see if it is worth doing something about.
The text was updated successfully, but these errors were encountered:
What version of Go are you using (
go version
)?1.10.1
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?I'm running this example on the Go Playground. Since the result is a syntax error, I don't believe operating system and processor architecture are relevant. (However, I can provide information about my machine if needed).
What did you do?
I attempted to run the following program (available on the Playground):
What did you expect to see?
I would expect the code to compile and run.
What did you see instead?
The Go compiler produced a syntax error:
Additional Info
The Go Spec defines a
RangeClause
as:The key point here is that an
Expression
is expected after the"range"
literal. Following the definitions in the spec shows that:CompositeLit
is anExpression
LiteralType
component of aCompositeLit
can be aTypeName
("T" in the example above).There is nothing in the spec that I could find to indicate that this syntax is not allowed.
The following examples do actually compile and run as expected:
Playground Link
Playground Link
Playground Link
I believe this is happening because the
'{'
after the type name is being interpreted as the beginning of theBLOCK
.I've recently spent some time studying the code for the Go parser. At first glance it seems like it would be difficult to distinguish between the beginning of a block and a composite literal expression without arbitrary lookahead. One possible solution is to simply add a note to the spec indicating that this syntax is not allowed.
It is also possible that the Go Spec contains many such edge cases, and noting all of them in a public document is impractical. I just wanted to bring some attention to this particular case to see if it is worth doing something about.
The text was updated successfully, but these errors were encountered: