Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gccgo: too many syntax errors for a simple mistake #14528

Open
rsc opened this issue Feb 26, 2016 · 0 comments

Comments

@rsc
Copy link
Contributor

commented Feb 26, 2016

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.

/cc @ianlancetaylor @paranoiacblack

@rsc rsc added this to the Gccgo milestone Feb 26, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.