Skip to content

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

Closed
@GottfriedHerold

Description

@GottfriedHerold

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.

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions