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
I get a strange syntax error when attempting to use a composite literal inside a for loop, even though as far as I can tell from the specification, this is valid syntax.
package main
import (
"fmt"
)
type Test struct{}
func main() {
for i := Test{};; {
fmt.Println("Hello, playground", i)
break
}
}
What did you expect to see?
No syntax errors
What did you see instead?
./prog.go:10:8: syntax error: cannot use i := Test as value
The text was updated successfully, but these errors were encountered:
A parsing ambiguity arises when a composite literal using the TypeName form of the LiteralType appears as an operand between the keyword and the opening brace of the block of an "if", "for", or "switch" statement, and the composite literal is not enclosed in parentheses, square brackets, or curly braces. In this rare case, the opening brace of the literal is erroneously parsed as the one introducing the block of statements. To resolve the ambiguity, the composite literal must appear within parentheses.
What version of Go are you using (
go version
)?Whatever is on the Go Playground.
Does this issue reproduce with the latest release?
Assuming Go Playground is up to date, yes.
What operating system and processor architecture are you using (
go env
)?N/A
What did you do?
Playground link: https://play.golang.org/p/yYCbpnPJdlL
I get a strange syntax error when attempting to use a composite literal inside a for loop, even though as far as I can tell from the specification, this is valid syntax.
What did you expect to see?
No syntax errors
What did you see instead?
./prog.go:10:8: syntax error: cannot use i := Test as value
The text was updated successfully, but these errors were encountered: