-
Notifications
You must be signed in to change notification settings - Fork 18k
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 "declared but not used" errors #50493
Labels
Milestone
Comments
Change https://golang.org/cl/378774 mentions this issue: |
Change https://golang.org/cl/378834 mentions this issue: |
Change https://golang.org/cl/379117 mentions this issue: |
jproberts
pushed a commit
to jproberts/go
that referenced
this issue
Jun 21, 2022
Consider the following program: package p func f() { x := 1 v := 2 switch v.(type) { case int: println(x) println(x / 0) case 1: } } Before this CL, the compiler prints: x.go:4:2: x declared but not used x.go:6:9: v (variable of type int) is not an interface x is in fact used, and other errors in the switch go undiagnosed. This commit fixes that problem by processing the switch statement even when the 'not an interface' error is reported. Now the compiler drops the spurious 'declared but not used' and adds two previously undiagnosed problems: x.go:6:9: v (variable of type int) is not an interface x.go:9:15: invalid operation: division by zero x.go:10:7: 1 is not a type go/types was printing roughly the same thing the compiler did before, and now still prints roughly the same thing the compiler does after. (The only differences are in the exact reported columns.) Fixes golang#50493. Change-Id: I317883f29077b1b4bbd0e8793617fd3bb31aa0f8 Reviewed-on: https://go-review.googlesource.com/c/go/+/379117 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
Not a release blocker but good to fix if easy.
Looks like because the switch header couldn't type-check, the bodies were not considered. And since the bodies were not considered, it looks like x was never used. The compiler should print the real error on line 6 and not print about line 4.
The text was updated successfully, but these errors were encountered: