Skip to content

cmd/vet: -shadow false positive #19490

Description

@thinkeridea

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 (
	"fmt"

	"github.com/pkg/errors"
)

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 {
			fmt.Println(err)
		}

		// Business logic mistakes need to deal with here
		fmt.Println(err)
	}()

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

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

}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions