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
Reduced from feedback I received from a student taking a class using Go.
The mistake in this program is the int in for int i := 0.
$ cat x.go
package p
func f() {
for int i := 0; i < n; i++ {
println(i)
}
}
The gc compiler and the go/parser both print two not terribly helpful syntax errors, but probably good enough:
$ go tool compile x.go
x.go:4: syntax error: unexpected name, expecting {
x.go:7: syntax error: unexpected }
$ gofmt x.go
x.go:4:10: expected '{', found 'IDENT' i
x.go:7:3: expected '}', found 'EOF'
Gccgo prints lots of errors:
$ gccgo x.go
x.go:4:10: error: expected ‘{’
for int i := 0; i < n; i++ {
^
x.go:4:10: error: expected ‘;’ or ‘}’ or newline
x.go:4:29: error: expected ‘;’ or ‘}’ or newline
for int i := 0; i < n; i++ {
^
x.go:7:1: error: expected declaration
}
^
x.go:4:18: error: reference to undefined name ‘i’
for int i := 0; i < n; i++ {
^
x.go:4:22: error: reference to undefined name ‘n’
for int i := 0; i < n; i++ {
^
x.go:4:25: error: reference to undefined name ‘i’
for int i := 0; i < n; i++ {
^
x.go:4:6: error: expected boolean expression
for int i := 0; i < n; i++ {
^
x.go:4:6: error: invalid use of type
x.go:4:20: error: value computed is not used
for int i := 0; i < n; i++ {
^
It does seem a little excessive. I'm a bit surprised that gccgo tries to type-check a program with syntax errors at all.
Reduced from feedback I received from a student taking a class using Go.
The mistake in this program is the
int
infor int i := 0
.The gc compiler and the go/parser both print two not terribly helpful syntax errors, but probably good enough:
Gccgo prints lots of errors:
It does seem a little excessive. I'm a bit surprised that gccgo tries to type-check a program with syntax errors at all.
/cc @ianlancetaylor @paranoiacblack
The text was updated successfully, but these errors were encountered: