Thank you for the insight. I didn't know that. But would it make more sense to throw an error in this case? Is there any missing points for an un-used private global variable? I feel like to file an issue on github but kind of unsure.
Vasko Zdravevski於 2017年12月31日星期日 UTC+8上午1時26分59秒寫道: > > I think this part of the spec explains this behavior as an "implementation > restriction": https://golang.org/ref/spec#Variable_declarations > > Implementation restriction: A compiler may make it illegal to declare a >> variable inside a function body >> <https://golang.org/ref/spec#Function_declarations> if the variable is >> never used. > > > On Saturday, December 30, 2017 at 9:51:39 AM UTC-7, leaf...@gmail.com > wrote: >> >> Hi all, suddenly I found the code >> package main >> >> import ( >> "fmt" >> ) >> >> var x=3 >> >> func main() { >> fmt.Println("Hello, playground") >> } >> >> >> It works fun, which surprised me. I mean, I get the idea that public >> global variable can be exported so it will not trigger "the declared but >> not used" error, but here x is a private variable: It cannot be used by >> other packages and it is not used anywhere, which to me seems to be a >> perfect match for an error. Did I miss something? >> Thanks in advance. >> > -- 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.