You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
by SRRajesh1989:
The text was updated successfully, but these errors were encountered: