dominikh / go-tools

Staticcheck - The advanced Go linter
https://staticcheck.dev
MIT License
6.01k stars 361 forks source link

SA4107: nilness check panics with 'unhandled type *ir.SliceToArray' #1529

Closed tdakkota closed 1 month ago

tdakkota commented 2 months ago

The output of 'staticcheck -debug.version'

staticcheck 2023.1.7 (v0.4.7)

Compiled with Go version: go1.22.2
Main module:
        honnef.co/go/tools@v0.4.7 (sum: h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=)
Dependencies:
        github.com/BurntSushi/toml@v1.2.1 (sum: h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=)
        golang.org/x/exp/typeparams@v0.0.0-20221208152030-732eee02a75a (sum: h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE=)
        golang.org/x/mod@v0.12.0 (sum: h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=)
        golang.org/x/sys@v0.11.0 (sum: h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=)
        golang.org/x/tools@v0.12.1-0.20230825192346-2191a27a6dc5 (sum: h1:Vk4mysSz+GqQK2eqgWbo4zEO89wkeAjJiFIr9bpqa8k=)

The output of 'go version'

go version go1.22.2 linux/amd64

Exactly which command you ran

staticcheck -checks SA4107 ./reproducer

Output of the command and what's wrong with the output

panic: internal error: unhandled type *ir.SliceToArray

goroutine 277 [running]:
honnef.co/go/tools/analysis/facts/nilness.impl.func1({0xa3a518, 0xc0002d63f0})
        /home/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.4.7/analysis/facts/nilness/nilness.go:239 +0x8a5
honnef.co/go/tools/analysis/facts/nilness.impl(0xc0005ccf70, 0xc000226140, 0xc000464e08)
        /home/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.4.7/analysis/facts/nilness/nilness.go:246 +0x348
honnef.co/go/tools/analysis/facts/nilness.run(0xc0005ccf70)
        /home/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.4.7/analysis/facts/nilness/nilness.go:66 +0x125
honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0xc0000e73b0, {0xa37b78?, 0xc000516500})
        /home/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.4.7/lintcmd/runner/runner.go:992 +0x71b
honnef.co/go/tools/lintcmd/runner.genericHandle({0xa37b78, 0xc000516500}, {0xa37b78?, 0xc0004b43c0?}, 0xc0000d1800, 0xc00038f370, 0xc000202ba0)
        /home/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.4.7/lintcmd/runner/runner.go:817 +0x11f
created by honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers in goroutine 163
        /home/tdakkota/go/pkg/mod/honnef.co/go/tools@v0.4.7/lintcmd/runner/runner.go:1061 +0x6a6

Where we can read the code you're running Staticcheck on

Reproducer:

package reproducer

func fillRandom[S ~[8]byte | ~[16]byte]() (s S) {
    var buf []byte
    return (S)(buf)
}

Issue also could be reproduced with golangci-lint v1.57.2 Pretty similar to #1397.

tdakkota commented 1 month ago

I've revisited this issue and it seems master version works just fine.

dominikh commented 1 month ago

git bisect claims that b3ee554011ba07e55a74da8c2e46de2accf60ec1 fixed this, which seems plausible. Thanks for having come back to this issue to confirm that it's no longer applicable.

https://github.com/dominikh/go-tools/issues/1522 suggests that the fix isn't part of the latest release. We'll rectify that soon.