Go version
go version go1.24.5 darwin/arm64
Output of go env
in your module/workspace:
AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/bkreitch/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/bkreitch/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/hx/91lpwn6j1yq000cp_j1np6k00000gq/T/go-build1319912065=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/bkreitch/github/bkreitch/golang-tools/go.mod'
GOMODCACHE='/Users/bkreitch/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/bkreitch/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.24.5/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/bkreitch/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.5/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.5'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
crossfile.go:
package crossfile
func ShadowGlobal() {
{
global := 1 // line 5
_ = global
}
_ = global
}
other.go:
package crossfile
var global int // line 3
$ shadow .
What did you see happen?
crossfile.go:5:3: declaration of "global" shadows declaration at line 3
What did you expect to see?
crossfile.go:5:3: declaration of "global" shadows declaration at line 3 in other.go
Comment From: gabyhelp
Related Issues
- x/tools/go/analysis/passes/shadow/cmd/shadow: Failure/success of the linter depends also on filename, not just the content #40758
- x/tools/go/analysis/passes/shadow: go vet shadow strict doesn't check global constant shadowing #72943
- cmd/vet: go vet -vettool=$(which shadow) errors in go1.13 only (flag provided but not defined: -unsafeptr) #34053 (closed)
- x/tools/go/analysis/passes/shadow/cmd/shadow: shadow inconsistent failures when var in code shadows a var in a test file #34557 (closed)
- cmd/vet: shadow false positive variable/type declaration in package block #18018 (closed)
- x/tools: shadow analyzer does not consider variables declared in for-range statement #44986
- x/tools/go/analysis/passes/shadow: "go vet --shadow" doesn't check global variable shadowing #35731 (closed)
- x/tools/go/analysis/passes/shadow: is confused by newtypes #49652
- x/tools/go/analysis/passes/shadow: fails to detect shadowed result identifiers #44875 (closed)
- x/tools/go/analysis/passes/shadow: shadowing not detected on deferred usage #36581
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: gopherbot
Change https://go.dev/cl/692396 mentions this issue: go/analysis/passes/shadow: include filename in cross-file shadow error messages
Comment From: mrkfrmn
CC @adonovan from owners.