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: not report slice as non-nil #45177

Open
komem3 opened this issue Mar 23, 2021 · 3 comments · May be fixed by golang/tools#291
Open

x/tools/go/analysis/passes/nilness: not report slice as non-nil #45177

komem3 opened this issue Mar 23, 2021 · 3 comments · May be fixed by golang/tools#291

Comments

@komem3
Copy link

@komem3 komem3 commented Mar 23, 2021

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

$ go version
go version go1.16 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

linux amd64

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1084334382=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I checked the following code by nilness

	f := make([]string, 0)
	if f == nil {
		log.Printf("nil")
	}

What did you expect to see?

I expected to detect comparison of non-nil and nil

What did you see instead?

not detect

@gopherbot gopherbot added this to the Unreleased milestone Mar 23, 2021
komem3 added a commit to komem3/tools that referenced this issue Mar 23, 2021
The slice produced by `s := []T{}` or `s := make([]T, 0)`
will always be non-nil. But, nilness could not detect it,
so I fixed it.

Fixes golang/go#45177
@gopherbot
Copy link

@gopherbot gopherbot commented Mar 23, 2021

Change https://golang.org/cl/303890 mentions this issue: go/analysis/passes/nilness: fixed slice not being considered as non-nil

@cagedmantis
Copy link
Contributor

@cagedmantis cagedmantis commented Mar 23, 2021

/cc @matloob

@timothy-king
Copy link
Contributor

@timothy-king timothy-king commented Mar 23, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants