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

cmd/compile: wrong line number in error message #13415

Closed
mdempsky opened this issue Nov 27, 2015 · 2 comments
Closed

cmd/compile: wrong line number in error message #13415

mdempsky opened this issue Nov 27, 2015 · 2 comments
Milestone

Comments

@mdempsky
Copy link
Member

At master, the Go source below produces an error message about line 6:

/tmp/x.go:6: x repeated on left side of :=

However, the error actually originates on line 5, and this was correctly reported at least in Go 1.4.2.

package foo

func f() {
    select {
    case x, x := <-func() chan int {
            c := make(chan int)
            return c
    }():
    }
}

The problem is (*parser).case_ doesn't access p.op (which is storing the LCOLAS token's line number) until after the p.expr() call, which might invalidate p.op if it contains another LCOLAS or LASOP token.

Best fix seems to be to just save lineno before calling p.next() like case LCOLAS in (*parser).simple_stmt. Then _yylex doesn't need to save lexlineno in yylval.i either.

CC @griesemer

@griesemer
Copy link
Contributor

@mdempsky Nice find, and thanks for the analysis!

@griesemer griesemer self-assigned this Nov 27, 2015
@griesemer griesemer added this to the Go1.6 milestone Nov 27, 2015
@gopherbot
Copy link

CL https://golang.org/cl/17248 mentions this issue.

@golang golang locked and limited conversation to collaborators Nov 27, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants