Re: [go-nuts] Inconsistent reporting of unused package variable initialized in init() but used elsewhere
Global vars are inherently problematic. As mirtchov...@gmail.com noted you are shadowing the global var in your first example. Which is why the global var isn't updated. I'm only responding because as a grey beard I am dismayed that today I see so many instances of global vars that should have more limited scope. On Sat, Feb 23, 2019 at 8:34 PM wrote: > Hello, > > It's likely that I'm misinterpreting the language spec. It's also easy to > circumvent by assigning the offending variable to _. Even if this turns > out to be complying with the spec, thought this post may help anyone else > looking up this forum for answers. > > https://play.golang.org/p/5P5vcebYkGj reports an unused error for a > package variable initialized inside init() even though it's used elsewhere. > In this case doSomething() has 2 return values, one of which is the package > variable while the other is local. > > https://play.golang.org/p/DBXdNOHAA2Z does not report an error for a > package variable initialized inside init(). In this case doSomething() has > a single return value. > > https://play.golang.org/p/pdz2mMnQ_EZ similarly does not report an error > for 2 package variables initialized inside init(). In this case > doSomething() has 2 return values as well. > > Thanks > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Kurtis Rader Caretaker of the exceptional canines Junior and Hank -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Inconsistent reporting of unused package variable initialized in init() but used elsewhere
in https://play.golang.org/p/5P5vcebYkGj you're shadowing s by creating a new variable via := this is a common go interview question :) On Sat, Feb 23, 2019 at 9:34 PM wrote: > > Hello, > > It's likely that I'm misinterpreting the language spec. It's also easy to > circumvent by assigning the offending variable to _. Even if this turns out > to be complying with the spec, thought this post may help anyone else looking > up this forum for answers. > > https://play.golang.org/p/5P5vcebYkGj reports an unused error for a package > variable initialized inside init() even though it's used elsewhere. In this > case doSomething() has 2 return values, one of which is the package variable > while the other is local. > > https://play.golang.org/p/DBXdNOHAA2Z does not report an error for a package > variable initialized inside init(). In this case doSomething() has a single > return value. > > https://play.golang.org/p/pdz2mMnQ_EZ similarly does not report an error for > 2 package variables initialized inside init(). In this case doSomething() has > 2 return values as well. > > Thanks > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Inconsistent reporting of unused package variable initialized in init() but used elsewhere
Hello, It's likely that I'm misinterpreting the language spec. It's also easy to circumvent by assigning the offending variable to _. Even if this turns out to be complying with the spec, thought this post may help anyone else looking up this forum for answers. https://play.golang.org/p/5P5vcebYkGj reports an unused error for a package variable initialized inside init() even though it's used elsewhere. In this case doSomething() has 2 return values, one of which is the package variable while the other is local. https://play.golang.org/p/DBXdNOHAA2Z does not report an error for a package variable initialized inside init(). In this case doSomething() has a single return value. https://play.golang.org/p/pdz2mMnQ_EZ similarly does not report an error for 2 package variables initialized inside init(). In this case doSomething() has 2 return values as well. Thanks -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.