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
package main
import "fmt"
func main() {
// Correct syntax.
a := []int{1, 3}
// Wrong syntax, a bug!
b := []int{1: 3}
fmt.Println("a", a)
fmt.Println("b", b)
}
What did you see happen?
The program prints:
a [1 3]
b [0 3]
No idea why the contents of b is as such.
What did you expect to see?
Since b is initialized not with a comma, the compiler should throw an syntax error.
The text was updated successfully, but these errors were encountered:
Go version
go version go1.23.2 linux/amd64
Output of
go env
in your module/workspace:What did you do?
I ran the following program, while intentionally mistyped a comma with a colon in slice initialization:
https://go.dev/play/p/uZWlwJV9cxI
What did you see happen?
The program prints:
No idea why the contents of
b
is as such.What did you expect to see?
Since
b
is initialized not with a comma, the compiler should throw an syntax error.The text was updated successfully, but these errors were encountered: