-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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: gc inconsistent about reporting "unused variable" errors #8560
Comments
gccgo also complains about this as an unused variable: $ gccgo x.go x.go:4:9: error: 'x' declared and not used switch x := interface{}(nil).(type) { ^ The spec makes this an implementation restriction, but go/types and gccgo agree with how the implementation restriction should be applied in this case. Making this a cmd/gc bug. Labels changed: added release-none, repo-main. Status changed to Accepted. |
CL https://golang.org/cl/10757 mentions this issue. |
… from go/types gc should ideally consider this an error too; see #8560. Change-Id: Ieee71c4ecaff493d7f83e15ba8c8a04ee90a4cf1 Reviewed-on: https://go-review.googlesource.com/10757 Reviewed-by: Robert Griesemer <gri@golang.org>
This is in milestone Unplanned. By my assignment should I infer you are requesting we reprioritize it? Normally Unplanned things have no assignee. |
Yes, that's what I meant. (Sorry if that was unclear or seemed passive-aggressive.) |
OK, reprioritized to Go 1.7, but that's still no guarantee. |
CL https://golang.org/cl/23528 mentions this issue. |
This fixes `go test go/types`. https://golang.org/cl/23487/ introduced this code which contains two unused variables (declared and assigned to, but never read). cmd/compile doesn't report the error due open issue #8560 (the variables are assigned to in a closure), but go/types does. The build bot only runs go/types tests in -short mode (which doesn't typecheck the std lib), hence this doesn't show up on the dashboard either. We cannot call b.Fatal and friends in the goroutine. Communicating the error to the invoking function requires a channel or a mutex. Unless the channel/sycnhronized variable is tested in each iteration that follows, the iteration blocks if there's a failure. Testing in each iteration may affect benchmark times. One could use a time-out but that time depends on the underlying system. Panicking seems good enough in this unlikely case; better than hanging or affecting benchmark times. Change-Id: Idce1172da8058e580fa3b3e398825b0eb4316325 Reviewed-on: https://go-review.googlesource.com/23528 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
@adg your report in #8560 (comment) was a bug that was already reported at #3059, in case you are interested in tracking that case. |
Out of interest, are there any known workarounds for the gorename issue #14596 (short of not using closures in this way across a codebase) that can be used to enable use of gorename in codebases such as that before this issue is resolved? |
This is revealed by the go/types package, which is stricter than the Go compiler about unused variables. See also: golang/go#8560
This is revealed by the go/types package, which is stricter than the Go compiler about unused variables. See also: golang/go#8560 Kubernetes-commit: e04b91facf180c17557a44e8e462858ea2936301
This is revealed by the go/types package, which is stricter than the Go compiler about unused variables. See also: golang/go#8560 Kubernetes-commit: e04b91facf180c17557a44e8e462858ea2936301
This is revealed by the go/types package, which is stricter than the Go compiler about unused variables. See also: golang/go#8560 Kubernetes-commit: e04b91facf180c17557a44e8e462858ea2936301
This is revealed by the go/types package, which is stricter than the Go compiler about unused variables. See also: golang/go#8560 Kubernetes-commit: e04b91facf180c17557a44e8e462858ea2936301
This is revealed by the go/types package, which is stricter than the Go compiler about unused variables. See also: golang/go#8560
This fixes `go test go/types`. https://golang.org/cl/23487/ introduced this code which contains two unused variables (declared and assigned to, but never read). cmd/compile doesn't report the error due open issue golang#8560 (the variables are assigned to in a closure), but go/types does. The build bot only runs go/types tests in -short mode (which doesn't typecheck the std lib), hence this doesn't show up on the dashboard either. We cannot call b.Fatal and friends in the goroutine. Communicating the error to the invoking function requires a channel or a mutex. Unless the channel/sycnhronized variable is tested in each iteration that follows, the iteration blocks if there's a failure. Testing in each iteration may affect benchmark times. One could use a time-out but that time depends on the underlying system. Panicking seems good enough in this unlikely case; better than hanging or affecting benchmark times. Change-Id: Idce1172da8058e580fa3b3e398825b0eb4316325 Reviewed-on: https://go-review.googlesource.com/23528 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This fixes `go test go/types`. https://golang.org/cl/23487/ introduced this code which contains two unused variables (declared and assigned to, but never read). cmd/compile doesn't report the error due open issue golang#8560 (the variables are assigned to in a closure), but go/types does. The build bot only runs go/types tests in -short mode (which doesn't typecheck the std lib), hence this doesn't show up on the dashboard either. We cannot call b.Fatal and friends in the goroutine. Communicating the error to the invoking function requires a channel or a mutex. Unless the channel/sycnhronized variable is tested in each iteration that follows, the iteration blocks if there's a failure. Testing in each iteration may affect benchmark times. One could use a time-out but that time depends on the underlying system. Panicking seems good enough in this unlikely case; better than hanging or affecting benchmark times. Change-Id: Idce1172da8058e580fa3b3e398825b0eb4316325 Reviewed-on: https://go-review.googlesource.com/23528 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Marked NeedsInvestigation since we need to re-establish the current facts. |
The Go 1.18 compiler correctly reports errors in these cases. |
The text was updated successfully, but these errors were encountered: