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

cmd/vet: -shadow false positive #19490

thinkeridea opened this issue Mar 10, 2017 · 2 comments


None yet
4 participants
Copy link

commented Mar 10, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.7.1 darwin/amd64

A sample code:

package main

import (


func main() {
	var err error

	defer func() {
		// Rear the mistake here is just a local error in processing logic, does not belong to the end to unified handling errors
		if err := errors.New(""); err != nil {

		// Business logic mistakes need to deal with here

	if err = errors.New(""); err != nil {

	if err = errors.New(""); err != nil {


Run the command go tool vet -shadow *.go to get :

sample.go:14: declaration of "err" shadows declaration at sample.go:10

I think there is no question of such code, in the main function in the defer if caused by using the local err statement.

@josharian josharian changed the title cmd/vet Variable scope inspection problems cmd/vet: -shadow false positive Mar 10, 2017


This comment has been minimized.

Copy link

commented Mar 10, 2017

Thanks for the report. The -shadow flag is known to have many false positives. That is why it is marked as experimental. I'm going to mark this as unplanned, meaning there are no concrete plans to fix it, but leave it open as a reference for any future efforts to reduce -shadow false positives.

@josharian josharian added this to the Unplanned milestone Mar 10, 2017

quasilyte added a commit to quasilyte/go-contributing-ru that referenced this issue Apr 1, 2018

tasks: add several new tracked tasks
New tasks include:
golang/go#19675 cmd/vet: report uses of -0 in float32/64 context
golang/go#19683 cmd/compile: eliminate usages of global lineno
golang/go#19670 x/tools/go/ssa: make opaqueType less annoying to use
golang/go#19636 encoding/base64: decoding is slow
golang/go#23471 x/perf/cmd/benchstat: tips or quickstart for newcomers
golang/go#19577 test: errorcheck support for intraline errors
golang/go#19490 cmd/vet: reduce the amount of false positives for -shadow mode
golang/go#19042 cmd/internal/obj: optimize wrapper method prologue for branch prediction
golang/go#19013 cmd/compile: add tool for understanding/debugging SSA rules

@ALTree ALTree added the NeedsFix label Sep 22, 2018


This comment has been minimized.

Copy link

commented Mar 27, 2019

Is it possible to somehow allow user to grant such false positives (such as the shellcheck disable directives)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.