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: internal error: no range for "project" #29338

Closed
bradleyjkemp opened this issue Dec 19, 2018 · 1 comment
Closed

cmd/vet: internal error: no range for "project" #29338

bradleyjkemp opened this issue Dec 19, 2018 · 1 comment

Comments

@bradleyjkemp
Copy link

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

$ go version
go version go1.11.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes, same error occurs on go version go1.11.4 darwin/amd64

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/bradleykemp/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/bradleykemp/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.4/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/6m/r713l1xj6_dcykbx21svs09h0000gp/T/go-build903451123=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Create minimal repro package:

vetshadowrepro
├── project
│   └── project.go
└── repro.go

repro.go has contents:

package vetshadowrepo

import (
    "vetshadowrepro/project"
)

func Repro() {
    project := &mocks.Project{}
    _ = project
}

and project.go has contents:

package mocks

type Project struct{}

Running go tool vet --shadow vetshadowrepro gives internal error in output:

vetshadowrepro/repro.go:8: internal error: no range for "project"

What did you expect to see?

No error because the project variable declaration does not shadow. Seems vet is confused by the import path being different to the package name.

What did you see instead?

Internal error:

vetshadowrepro/repro.go:8: internal error: no range for "project"
@bcmills
Copy link
Contributor

bcmills commented Dec 19, 2018

go tool vet will no longer be supported in Go 1.12 (see #28869), and the -shadow flag
was explicitly experimental to begin with:

"check for shadowed variables (experimental; must be set explicitly)",

The good news is, go help vet mentions the shadow check explicitly:

For example, the 'shadow' analyzer can be built and run using these commands:

go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
go vet -vettool=$(which shadow)

And it seems to work; at the very least it doesn't crash:

_gopath/src/vetshadowrepro$ GO111MODULE=off go vet -vettool=$(which shadow) vetshadowrepro/...

_gopath/src/vetshadowrepro$ GO111MODULE=on go vet -vettool=$(which shadow) vetshadowrepro/...

@bcmills bcmills closed this as completed Dec 19, 2018
@golang golang locked and limited conversation to collaborators Dec 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants