I found a strange behavior (well, I would call it a bug) of for-range over a composite literal where the literal type is a user type (or alias). This is true for both maps and array/slices, but the following example is with a slice.
My guess is that at the compiler level the for-range statement is expecting [] followed by {} in order to recognize the composite literal, and misses the case when the literal type is a user type (i.e. type List []int). Bug or feature ? :) -- Raffaele package main import "fmt" type Int int type List []int func main() { // this works source := List{1, 2, 3, 4, 5} for _, x := range source { fmt.Println(x) } // this works for _, x := range []int{1, 2, 3, 4, 5} { fmt.Println(x) } // this works for _, x := range []Int{1, 2, 3, 4, 5} { fmt.Println(x) } // this doesn't for _, x := range List{1, 2, 3, 4, 5} { fmt.Println(x) } } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.