Skip to content

Unused variable check no enforced for package scope #222

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

Closed
gopherbot opened this issue Nov 16, 2009 · 1 comment
Closed

Unused variable check no enforced for package scope #222

gopherbot opened this issue Nov 16, 2009 · 1 comment

Comments

@gopherbot
Copy link
Contributor

by SRRajesh1989:

A code like:

package main
var strx, inty = "hello", 123
func main() {
}

Note that strx and inty are not used anywhere in the program. But go fail
to report compilation error because of unused variable. But making that
declaration inside the function like below, generates compilation error.

package main
func main() {
var strx, inty = "hello", 123
}

Is this the intended behavior? It will be better to report error in both
the cases.
@rsc
Copy link
Contributor

rsc commented Nov 17, 2009

Comment 1:

The main reason we allow these is that this check is intended to catch:
    i := 0;
    if cond {
        i := 1;
    }
    println(i)
which always prints 0.  The global declarations are not involved.
Often it is useful to declare top-level constants that may not yet
be used.
The linker will throw them away when linking the program, so
they don't cause bloat in the binaries.

Owner changed to r...@golang.org.

Status changed to WontFix.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants