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

Closed
komem3 opened this issue Mar 23, 2021 · 3 comments
Closed

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

komem3 opened this issue Mar 23, 2021 · 3 comments
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@komem3
Copy link

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 the Tools This label describes issues relating to any tools in the x/tools repository. label Mar 23, 2021
@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

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

@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 23, 2021
@cagedmantis
Copy link
Contributor

/cc @matloob

@timothy-king timothy-king added the Analysis Issues related to static analysis (vet, x/tools/go/analysis) label Mar 23, 2021
@timothy-king
Copy link
Contributor

/cc @guodongli-google

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Apr 2, 2021
komem3 added a commit to komem3/tools that referenced this issue Jul 16, 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
@golang golang locked and limited conversation to collaborators May 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants