Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: cmd/vet: warn when zero values make explicit initialisation unnecessary #21362

jokeyrhyme opened this issue Aug 9, 2017 · 2 comments


Copy link

@jokeyrhyme jokeyrhyme commented Aug 9, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.8.3 darwin/amd64

What operating system and processor architecture are you using (go env)?


What did you do?

import (

type Thing struct {
  mutex sync.RWMutex
  time time.Time

func NewThing() *Thing {
  return &Thing{
    mutex: sync.RWMutex{},
    time: time.Unix(0, 0),

What did you expect to see?

Proposal: go vet should warn when initialising a value is unnecessary, i.e. when the zero value for the type is effectively equal to the explicitly initialised value

As someone new to the language, I have not memorised which types have a zero value and what those zero values are

I will look these up now that I know about them, but go vet could help me and others in this case

What did you see instead?

go vet does not indicate any issues about unnecessary initialisation

@gopherbot gopherbot added this to the Proposal milestone Aug 9, 2017
@gopherbot gopherbot added the Proposal label Aug 9, 2017
Copy link

@ianlancetaylor ianlancetaylor commented Aug 9, 2017

See cmd/vet/README for guidelines for vet checks. I think this one fails the "correctness" criterion: unnecessary initialization is not a bug.

Copy link

@jokeyrhyme jokeyrhyme commented Aug 9, 2017

yep, found it:


Vet's tools are about correctness, not style. A vet check must identify real or
potential bugs that could cause incorrect compilation or execution. A check that
only identifies stylistic points or alternative correct approaches to a situation
is not acceptable.

I agree that unnecessary initialisation is not a bug

I've filed this as a suggestion for golint instead: golang/lint#317

@jokeyrhyme jokeyrhyme closed this Aug 9, 2017
@golang golang locked and limited conversation to collaborators Aug 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants