x/tools/go/analysis/analysistest: facts are sometimes not inherited from dependent analyzers #59164
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputGO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/Users/ericchiang/Library/Caches/go-build" GOENV="/Users/ericchiang/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/ericchiang/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/ericchiang/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.20.2" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/dev/null" GOWORK="" CGO_CFLAGS="-O2 -g" CGO_CPPFLAGS="" CGO_CXXFLAGS="-O2 -g" CGO_FFLAGS="-O2 -g" CGO_LDFLAGS="-O2 -g" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/d1/wpvcpdrs2tlgn5xs3_xm88th0000gn/T/go-build2810425986=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
Wrote an analyzer that depends on facts from another analyzer. In my case, this was a dead code analyzer that depended on facts omitted by a "usage" analyzer. Per the docs in the analysis package:
https://pkg.go.dev/golang.org/x/tools/go/analysis#hdr-Modular_analysis_with_Facts
I modeled this as an analyzer that read facts from another.
However, when I tried to test with analysistest, the analyzer wasn't seeing the facts:
What did you expect to see?
Analyzer to see the facts exported by the "factAnalyzer".
What did you see instead?
It appears that when analyzing the same package, facts aren't inherited:
https://github.com/golang/tools/blob/fa556487c5c2be818dd2bab43e16f1afa06f8f89/go/analysis/internal/checker/checker.go#L721-L732
So the test fails:
The text was updated successfully, but these errors were encountered: