Odd syntax error difference when in testing

1,877 views
Skip to first unread message

Brendan Tracey

unread,
Apr 19, 2013, 5:08:05 PM4/19/13
to golan...@googlegroups.com
When one forgets an equality statement before a range, the compiler normally gives a very nice error
 prog.go:7: syntax error: unexpected range, expecting := or = or comma  


However, running the same code using go test 

func TestFoo(t *testing.T){

     slc := []int{1,2,3}

     for _,val range slc{

          fmt.Println("Hello, playground")

     }

}

gives the error "expected 1 expression". Is there a reason that I am missing for this difference? The first error is way more useful.

Rob Pike

unread,
Apr 19, 2013, 5:29:53 PM4/19/13
to Brendan Tracey, golan...@googlegroups.com
Go test uses the go/parser package to build the test, which is then
compiled by the usual compiler. The syntax errors can therefore
differ.

-rob
Reply all
Reply to author
Forward
0 new messages