-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: spurious foo.func1 redeclared in this block
#17758
Comments
At least we get an error. Not urgent. |
Interestingly when the content of the repeated functions differs, we get the expected single warning package main
func foo() {
_ = func() {}
}
func foo() {
_ = "hey"
}
func main() {} tmp/sandbox704696438/main.go:7: foo redeclared in this block
previous declaration at tmp/sandbox704696438/main.go:3 In the reported issue log the compiler seems to be peeking in to compare bodies of the functions hence the spurious main.go:8: foo.func1 redeclared in this block
previous declaration at tmp/sandbox669345157/main.go:4 and then package main
func foo() {
_ = func() {}
_ = func() { _ = "hey" }
}
func foo() {
_ = func() {}
_ = func() { _ = "hey" }
}
func main() {} tmp/sandbox613823462/main.go:8: foo redeclared in this block
previous declaration at tmp/sandbox613823462/main.go:3
tmp/sandbox613823462/main.go:9: foo.func1 redeclared in this block
previous declaration at tmp/sandbox613823462/main.go:4
tmp/sandbox613823462/main.go:10: foo.func2 redeclared in this block
previous declaration at tmp/sandbox613823462/main.go:5 |
@odeke-em Your first example only shows a single error because the anonymous function isn't declared a second time. It's isn't really "comparing the bodies" as much as compiling them. Anonymous functions still have a name, which is a concatenation of the outer function's name, some static text, and a counter. Having two outer functions with the same name (the first error) with anonymous functions inside will lead to these names also clashing. |
Ah I see, thanks for the explanation @dominikh, TIL! |
First error is from Root cause: For both of the above calls, Here's full stacktrace, obtained by putting
|
Change https://golang.org/cl/248517 mentions this issue: |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.7.3 linux/amd64
go version devel +53fc330 Tue Nov 1 04:42:33 2016 +0000 linux/amd64
What did you do?
https://play.golang.org/p/m7Z1qHv6ak
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: