You are correct sir, and unfortunately, go vet doesn't find it either.
But if you lint your code with golangci-lint (
https://github.com/golangci/golangci-lint)
the deadcode linter will find it for you.

On Wed, Feb 3, 2021 at 9:35 AM Danny Hart <iamdanielh...@gmail.com> wrote:

> Hello all,
>
> Very new gopher here (also first time using Groups, please excuse poor
> etiquette).  I was curious why the following basic program compiles with an
> unused var. Is it the case that the compiler only complains about unused
> vars in a function body?
>
> package main
>
> import (
> "fmt"
> )
>
> var (
> x int
> )
>
> func main() {
> fmt.Println("Hello, playground")
> }
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/d4e80994-8f42-4fe9-888f-26dd973ccbc3n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/d4e80994-8f42-4fe9-888f-26dd973ccbc3n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
*Matt Holiday*
Senior Gopher, Marketing Technologies

620 Eighth Avenue

New York, NY 10018

matthew.holi...@nytimes.com

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAGSa1CnQ4D698AEZACqoE_dCCmJEy4V5exSj3Y50oBGWz4mSLA%40mail.gmail.com.

Reply via email to