-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: consistently report "declared but not used" errors - needs release notes #49214
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
Comments
This is spec-compatible, and it is also compatible with gccgo, as well as go vet. Since there is no spec change, we don't really need a proposal here, |
Leaving open to add text to release notes. |
Change https://golang.org/cl/366274 mentions this issue: |
Problem
Per the spec:
a compiler may report errors for unused variables. The pre-1.18 compiler fails to do so if a variable is never used but set inside a function literal. Example:
There is no use of
p
in this program but until now the compiler didn't report an error. See also issues #8560 and #46004.The new 1.18 compiler front-end uses a
go/types
-based type checker (types2
) which correctly reports an error in cases like these; so doesgo/types
, and so doesgo/vet
.Proposal
The compiler should consistently report such errors from now on. This does not affect existing code that passes
go/vet
. There is a chance that code that used to compile (such as the example above) won't compile anymore; it is also likely that such code was not correct in the first place.For existing code that won't compile anymore there are several work-arounds:
_ = x
for an unused variablex
).Implementation
If the proposal is accepted, nothing needs to be done; this is already the new behavior of the compiler.
If the proposal is not accepted, the compiler needs to be adjusted such that any access of a variable in a function literal is considered a "use".
The text was updated successfully, but these errors were encountered: