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 redeclaration error #20415

Closed
rsc opened this issue May 18, 2017 · 5 comments
Closed

cmd/compile: wrong line number in redeclaration error #20415

rsc opened this issue May 18, 2017 · 5 comments
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented May 18, 2017

$ n zz_test.go
    1	package z
    2	
    3	func f() {
    4		_ = g[:]
    5	}
    6	
    7	var g [1]byte
    8	
    9	func f2() {
   10		for g := 0; g < 2; g++ {
   11			go func(g int) {
   12			}(g)
   13		}
   14	}
   15	
   16	var g interface{}
$ go test zz_test.go
# command-line-arguments
./zz_test.go:4:7: cannot slice g (type interface {})
./zz_test.go:16:5: g redeclared in this block
	previous declaration at ./zz_test.go:11:13
FAIL	command-line-arguments [build failed]
$ 

The conflicting "previous declaration" is at line 7, not line 11.

This is reduced from a much larger example; I was very confused for a bit as to how one global declaration could possibly be conflicting with a closure parameter name. I had to guess to look for a different global variable by hand.

/cc @griesemer @mdempsky

@rsc rsc added this to the Go1.9 milestone May 18, 2017
@griesemer griesemer self-assigned this May 18, 2017
@odeke-em
Copy link
Member

At least it doesn't happen on Go1.8 as per https://play.golang.org/p/WNexAimVXU
screen shot 2017-05-20 at 2 46 10 am
but happens on tip at 2d20ded

@odeke-em
Copy link
Member

And according to the code Maury, eaf02e1 seems to be the father of the regression:
Commit:

@griesemer
Copy link
Contributor

Thanks, @odeke-em for tracking this down.

@griesemer
Copy link
Contributor

Simpler repro-case:

package p

var g byte

func f(g int) {}

var g interface{}

@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators May 22, 2018
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

4 participants