Code compiles with unused var block

86 views
Skip to first unread message

Danny Hart

unread,
Feb 3, 2021, 11:36:07 AM2/3/21
to golang-nuts
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")
}

Matthew Holiday

unread,
Feb 3, 2021, 11:45:50 AM2/3/21
to Danny Hart, golang-nuts
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.

--
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...@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.


--
Matt Holiday
Senior Gopher, Marketing Technologies

620 Eighth Avenue

New York, NY 10018

matthew...@nytimes.com

Danny H

unread,
Feb 3, 2021, 1:14:50 PM2/3/21
to golang-nuts
Thanks so much Matt, appreciate your wisdom.
Reply all
Reply to author
Forward
0 new messages