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

Comments

Projects
None yet
4 participants
@rsc
Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

commented May 20, 2017

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

This comment has been minimized.

Copy link
Member

commented May 20, 2017

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

@griesemer

This comment has been minimized.

Copy link
Contributor

commented May 22, 2017

Thanks, @odeke-em for tracking this down.

@griesemer

This comment has been minimized.

Copy link
Contributor

commented May 22, 2017

Simpler repro-case:

package p

var g byte

func f(g int) {}

var g interface{}
@gopherbot

This comment has been minimized.

Copy link

commented May 22, 2017

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

@gopherbot gopherbot closed this in d79bb78 May 22, 2017

@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.
You can’t perform that action at this time.