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

x/tools/go/analysis/passes/nilness: bogus "impossible condition: non-nil == nil" that is actually possible #66835

Open
GottfriedHerold opened this issue Apr 15, 2024 · 1 comment
Assignees
Labels
Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@GottfriedHerold
Copy link

GottfriedHerold commented Apr 15, 2024

Go version

go version go1.21.3 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/gottfried/.cache/go-build'
GOENV='/home/gottfried/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/gottfried/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/gottfried/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/gottfried/sdk/go1.21.3'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/gottfried/sdk/go1.21.3/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/gottfried/Bandersnatch/go.mod'
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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2158884728=/tmp/go-build -gno-record-gcc-switches'

What did you do?

The following minimal example function

func F[T error](x T) {
	if any(x) == nil {
		panic(0) // or whatever
	}
}

triggers a "impossible condition: non-nil == nil (nilness) cond" warning by the nilness analyser.
I'm using vscode with its own gopls integration (which, as opposed to calling go vet (by default, unless opted-in) actually performs nilness analysis, as far as I understand).
Of course, the nilness check is actually not bogus:
Calling F[error](nil) will happily run panic(0).
I suspect the analyser somehow thinks T is a non-interface type.

What did you see happen?

An impossible condition: non-nil == nil nilness (cond) warning flagged by my IDE

What did you expect to see?

no warning.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Apr 15, 2024
@gopherbot gopherbot added this to the Unreleased milestone Apr 15, 2024
@gopherbot
Copy link

Change https://go.dev/cl/578938 mentions this issue: go/analysis/passes/nilness: fix bug with MakeInterface(TypeParam)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants