Hi,
I experienced a weird compiling error in my go program. I have such code snippet to reproduce it:
package main
import "fmt"
type T struct {
Field int
}
func (t T) Next() T {
return T{t.Field+1}
}
func main() {
/* Got error at next for statement:
prog.go:14: syntax error: unexpected { at end of statement
prog.go:17: syntax error: non-declaration statement outside function body
for t := T{1}; t.Field < 10; t = t.Next() {
fmt.Println(t)
} */
// This is fine
t2 := T{1}
for ; t2.Field < 10; t2 = t2.Next() {
fmt.Println(t2)
}
}
I can understand the compiler may consider the first '{' be the beginning of a block. Do we consider it a bug? If the behavior is intentional, can we output less confusing error message?
Thanks.
Sheng