golangci / golangci-lint

Fast linters runner for Go
https://golangci-lint.run
GNU General Public License v3.0
15.53k stars 1.38k forks source link

Panic, from staticcheck #2859

Closed sukki37 closed 2 years ago

sukki37 commented 2 years ago

Welcome

Description of the problem

golangci-lint run --disable-all -E staticcheck ./...
ERRO [runner] Panic: buildir: package "shuffle" (isInitialPkg: true, needAnalyzeSource: true): in github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.init: cannot convert github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.fixedLengthShuffle (func[T github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.fixedLength](vs []T, ws []T, sels []int64) []T) to func(vs []int8, ws []int8, sels []int64) []int8: goroutine 25269 [running]:
runtime/debug.Stack()
        runtime/debug/stack.go:24 +0x68
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:101 +0x104
panic({0x10304c6a0, 0x1400f242950})
        runtime/panic.go:838 +0x204
honnef.co/go/tools/go/ir.emitConv(0x14008c66b40, {0x1031cab98, 0x14008c66c80}, {0x1031c0d80?, 0x1400ca5c8c0}, {0x0, 0x0})
        honnef.co/go/tools@v0.3.1/go/ir/emit.go:293 +0xb0c
honnef.co/go/tools/go/ir.emitStore(0x14008c66b40, {0x1031cac68, 0x1400bdff220}, {0x1031cab98, 0x14008c66c80}, {0x0, 0x0})
        honnef.co/go/tools@v0.3.1/go/ir/emit.go:302 +0x68
honnef.co/go/tools/go/ir.(*address).store(0x14007300f40, 0x14008c66b40?, {0x1031cab98?, 0x14008c66c80?}, {0x0?, 0x0?})
        honnef.co/go/tools@v0.3.1/go/ir/lvalue.go:37 +0x5c
honnef.co/go/tools/go/ir.(*builder).assign(0x103088b80?, 0x14011ac4930?, {0x1031c6050, 0x14007300f40}, {0x1031c3be0?, 0x1401564dbf0?}, 0x0?, 0x0, {0x0, 0x0})
        honnef.co/go/tools@v0.3.1/go/ir/builder.go:542 +0x628
honnef.co/go/tools/go/ir.(*Package).build(0x14016ad55f0)
        honnef.co/go/tools@v0.3.1/go/ir/builder.go:2568 +0x90c
sync.(*Once).doSlow(0x1400b7860e0?, 0x1400bdc20f0?)
        sync/once.go:68 +0x10c
sync.(*Once).Do(...)
        sync/once.go:59
honnef.co/go/tools/go/ir.(*Package).Build(...)
        honnef.co/go/tools@v0.3.1/go/ir/builder.go:2505
honnef.co/go/tools/internal/passes/buildir.run(0x1401336c8f0)
        honnef.co/go/tools@v0.3.1/internal/passes/buildir/buildir.go:86 +0x28c
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0x140058ff3d0)
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:187 +0x96c
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:105 +0x24
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0x14001c79860, {0x102d7b99c, 0x7}, 0x14002ea2730)
        github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x48
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0x10296a640?)
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:104 +0x78
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0x140058ff3d0)
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xb4
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x16c 
WARN [runner] Can't run linter staticcheck: staticcheck: buildir: package "shuffle" (isInitialPkg: true, needAnalyzeSource: true): in github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.init: cannot convert github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.fixedLengthShuffle (func[T github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.fixedLength](vs []T, ws []T, sels []int64) []T) to func(vs []int8, ws []int8, sels []int64) []int8 
ERRO Running error: 1 error occurred:
        * can't run linter staticcheck: staticcheck: buildir: package "shuffle" (isInitialPkg: true, needAnalyzeSource: true): in github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.init: cannot convert github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.fixedLengthShuffle (func[T github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.fixedLength](vs []T, ws []T, sels []int64) []T) to func(vs []int8, ws []int8, sels []int64) []int8

Version of golangci-lint

```console golangci-lint --version golangci-lint has version 1.46.1 built from 044f0a17 on 2022-05-12T09:23:45Z ```

Configuration file

no .golongci.yml, only enable staticcheck by command line. ```console $ cat .golangci.yml # paste output here ```

Go environment

```console go version go1.18.1 darwin/arm64 GO111MODULE="on" GOARCH="arm64" GOBIN="" GOCACHE="/Users/maomao/Library/Caches/go-build" GOENV="/Users/maomao/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/maomao/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/maomao/go" GOPRIVATE="" GOPROXY="https://mirrors.tencent.com/go,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64" GOVCS="" GOVERSION="go1.18.1" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/Users/maomao/code/matrixone/go.mod" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/v4/9c736kps76jbbvf97snf3s9w0000gn/T/go-build2062840899=/tmp/go-build -gno-record-gcc-switches -fno-common" ```

Verbose output of running

```console INFO [config_reader] Config search paths: [./ /Users/maomao/code/matrixone /Users/maomao/code /Users/maomao /Users /] INFO [lintersdb] Active 1 linters: [staticcheck] INFO [loader] Go packages loading at mode 575 (files|imports|types_sizes|compiled_files|deps|exports_file|name) took 1.702499333s INFO [runner/filename_unadjuster] Pre-built 2 adjustments in 94.23975ms INFO [linters context/goanalysis] analyzers took 1m14.602552617s with top 10 stages: buildir: 32.000991883s, fact_purity: 2.532383466s, nilness: 2.500163266s, typedness: 2.372219817s, fact_deprecated: 2.121536948s, SA5012: 1.916474125s, SA1012: 1.229031041s, SA4030: 1.048752863s, SA1004: 1.005119633s, SA4023: 896.485827ms ERRO [runner] Panic: buildir: package "shuffle" (isInitialPkg: true, needAnalyzeSource: true): in github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.init: cannot convert github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.fixedLengthShuffle (func[T github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.fixedLength](vs []T, ws []T, sels []int64) []T) to func(vs []int8, ws []int8, sels []int64) []int8: goroutine 21455 [running]: runtime/debug.Stack() runtime/debug/stack.go:24 +0x68 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1() github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:101 +0x104 panic({0x105a686a0, 0x1404bab2ac0}) runtime/panic.go:838 +0x204 honnef.co/go/tools/go/ir.emitConv(0x14019ecc280, {0x105be6b98, 0x14019ecc3c0}, {0x105bdcd80?, 0x1405a52fd80}, {0x0, 0x0}) honnef.co/go/tools@v0.3.1/go/ir/emit.go:293 +0xb0c honnef.co/go/tools/go/ir.emitStore(0x14019ecc280, {0x105be6c68, 0x14041b78410}, {0x105be6b98, 0x14019ecc3c0}, {0x0, 0x0}) honnef.co/go/tools@v0.3.1/go/ir/emit.go:302 +0x68 honnef.co/go/tools/go/ir.(*address).store(0x1404b2788c0, 0x14019ecc280?, {0x105be6b98?, 0x14019ecc3c0?}, {0x0?, 0x0?}) honnef.co/go/tools@v0.3.1/go/ir/lvalue.go:37 +0x5c honnef.co/go/tools/go/ir.(*builder).assign(0x105aa4b80?, 0x1405b0f0990?, {0x105be2050, 0x1404b2788c0}, {0x105bdfbe0?, 0x1405a175d10?}, 0x0?, 0x0, {0x0, 0x0}) honnef.co/go/tools@v0.3.1/go/ir/builder.go:542 +0x628 honnef.co/go/tools/go/ir.(*Package).build(0x1405ba78bd0) honnef.co/go/tools@v0.3.1/go/ir/builder.go:2568 +0x90c sync.(*Once).doSlow(0x1405a2275e0?, 0x1405a540370?) sync/once.go:68 +0x10c sync.(*Once).Do(...) sync/once.go:59 honnef.co/go/tools/go/ir.(*Package).Build(...) honnef.co/go/tools@v0.3.1/go/ir/builder.go:2505 honnef.co/go/tools/internal/passes/buildir.run(0x1405a547ad0) honnef.co/go/tools@v0.3.1/internal/passes/buildir/buildir.go:86 +0x28c github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0x14005983550) github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:187 +0x96c github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2() github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:105 +0x24 github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0x14002155770, {0x10579799c, 0x7}, 0x140026b2f30) github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x48 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0x105386640?) github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:104 +0x78 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0x14005983550) github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xb4 created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x16c WARN [runner] Can't run linter staticcheck: staticcheck: buildir: package "shuffle" (isInitialPkg: true, needAnalyzeSource: true): in github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.init: cannot convert github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.fixedLengthShuffle (func[T github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.fixedLength](vs []T, ws []T, sels []int64) []T) to func(vs []int8, ws []int8, sels []int64) []int8 INFO [runner] processing took 6.625µs with stages: skip_dirs: 1.709µs, nolint: 1.667µs, max_same_issues: 1.541µs, max_from_linter: 458ns, cgo: 334ns, max_per_file_from_linter: 250ns, uniq_by_line: 167ns, path_prettifier: 125ns, filename_unadjuster: 125ns, sort_results: 42ns, path_prefixer: 42ns, source_code: 42ns, identifier_marker: 41ns, skip_files: 41ns, severity-rules: 41ns, exclude: 0s, diff: 0s, autogenerated_exclude: 0s, exclude-rules: 0s, path_shortener: 0s INFO [runner] linters took 10.61532175s with stages: staticcheck: 10.613429875s ERRO Running error: 1 error occurred: * can't run linter staticcheck: staticcheck: buildir: package "shuffle" (isInitialPkg: true, needAnalyzeSource: true): in github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.init: cannot convert github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.fixedLengthShuffle (func[T github.com/matrixorigin/matrixone/pkg/vectorize/shuffle.fixedLength](vs []T, ws []T, sels []int64) []T) to func(vs []int8, ws []int8, sels []int64) []int8 INFO Memory: 125 samples, avg is 1374.6MB, max is 4159.3MB INFO Execution took 12.429372958s ```

Code example or link to a public repository

https://github.com/matrixorigin/matrixone

boring-cyborg[bot] commented 2 years ago

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

ldez commented 2 years ago

Hello,

The problem seems to only affect staticcheck inside golangci-lint, the standalone binary of staticcheck seems to work. We need to investigate.

dominikh commented 2 years ago

A quick glance tells me that golangci-lint doesn't populate types.Info.Instances.

sukki37 commented 2 years ago

Hello,

The problem seems to only affect staticcheck inside golangci-lint, the standalone binary of staticcheck seems to work. We need to investigate.

Hi, how is this issue going?

metalmatze commented 2 years ago

Not sure if this is super helpful, but maybe for testing a fix. The same issue arises when running v1.46.2 against: github.com/segmentio/parquet-go

WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: buildir: package "parquet" (isInitialPkg: false, needAnalyzeSource: true): in github.com/segmentio/parquet-go.nullIndexFuncOf: cannot convert github.com/segmentio/parquet-go.nullIndex (func[T comparable](a github.com/segmentio/parquet-go.array) int) to github.com/segmentio/parquet-go.nullIndexFunc 
erikgeiser commented 2 years ago

I believe I've encoutered the same issue with goanalysis_metalinter running v1.46.2 against https://github.com/erikgeiser/promptkit:

ERRO Running error: 1 error occurred:
    * can't run linter goanalysis_metalinter: goanalysis_metalinter: buildir: package "selection" (isInitialPkg: true, needAnalyzeSource: true): in github.com/erikgeiser/promptkit/selection.New: cannot convert github.com/erikgeiser/promptkit/selection.FilterContainsCaseInsensitive (func[T any](filter string, choice *github.com/erikgeiser/promptkit/selection.Choice[T]) bool) to func(filterText string, choice *github.com/erikgeiser/promptkit/selection.Choice[T]) bool
forsaken628 commented 2 years ago
package main

type ColScan[T any] struct {
    Pick func(item *T) any
}

type Foo struct {
    A string
}

func main() {
    _ = ColScan[Foo]{
        Pick: Jointer[int, Foo],
    }
}

func Jointer[T, V any](*V) any {
    var z T
    return &z
}

ERRO [runner] Panic: buildir: package "main" (isInitialPkg: true, needAnalyzeSource: true): in xx/aaa.main: cannot convert xx/aaa.Jointer (funcT, V any any) to func(item *xx/aaa.Foo) any: goroutine 543 [running]:

AlmogBaku commented 2 years ago

Is anyone familiar with a workaround? or at least a temporary way to silence this error?

ldez commented 2 years ago

There is no other workaround than disabling staticcheck rules (staticcheck, gosimple, stylecheck, unused)

firelizzard18 commented 2 years ago

I am running into this same issue on this commit. I updated to 1.46.2, disabled my custom rules, and ran go run github.com/golangci/golangci-lint/cmd/golangci-lint run. I get the following panic:

ERRO [runner] Panic: buildir: package "record" (isInitialPkg: true, needAnalyzeSource: true): in gitlab.com/accumulatenetwork/accumulate/internal/database/record.init: cannot convert gitlab.com/accumulatenetwork/accumulate/internal/database/record.copyValue (func[T any](v T) T) to func(uint64) uint64: goroutine 16309 [running]:
runtime/debug.Stack()
        /usr/lib/go/src/runtime/debug/stack.go:24 +0x65
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
        /home/firelizzard/go/pkg/mod/github.com/golangci/golangci-lint@v1.46.2/pkg/golinters/goanalysis/runner_action.go:101 +0x155
panic({0x13ef2c0, 0xc014c9b140})
        /usr/lib/go/src/runtime/panic.go:838 +0x207
honnef.co/go/tools/go/ir.emitConv(0xc0093f83c0, {0x18072f0, 0xc0093f9540}, {0x17fcaf0?, 0xc025c26640}, {0x17fc528, 0xc0216aedb0})
        /home/firelizzard/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/emit.go:293 +0xd29
honnef.co/go/tools/go/ir.emitStore(0xc0093f83c0, {0x1807220, 0xc01a3bbbc0}, {0x18072f0, 0xc0093f9540}, {0x17fc528, 0xc0216aedb0})
        /home/firelizzard/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/emit.go:302 +0x7f
honnef.co/go/tools/go/ir.(*address).store(0xc016ff20e0, 0xc01a3bbb00?, {0x18072f0?, 0xc0093f9540?}, {0x17fc528?, 0xc0216aedb0?})
        /home/firelizzard/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/lvalue.go:37 +0x53
honnef.co/go/tools/go/ir.(*storebuf).emit(0xc0093f83c0?, 0xc0093f83c0)
        /home/firelizzard/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:455 +0xeb
honnef.co/go/tools/go/ir.(*builder).addr(0xc029528420?, 0xc0093f83c0, {0x17ffb88?, 0xc038ac5e40}, 0x1)
        /home/firelizzard/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:344 +0x325
honnef.co/go/tools/go/ir.(*builder).expr0(0xc01c4b1a28, 0xc0093f83c0, {0x1800218?, 0xc0052660e0?}, {0x7, {0x17fcac8, 0xc01d1a4be0}, {0x0, 0x0}})
        /home/firelizzard/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:630 +0xf1
honnef.co/go/tools/go/ir.(*builder).expr(0x8?, 0xc0093f83c0, {0x1800218?, 0xc0052660e0?})
        /home/firelizzard/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:566 +0x1db
honnef.co/go/tools/go/ir.(*builder).assign(0xc001a1fb80?, 0x0?, {0x1802600, 0xc016ff20a0}, {0x1800218?, 0xc0052660e0?}, 0x20?, 0x0, {0x0, 0x0})
        /home/firelizzard/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:538 +0x605
honnef.co/go/tools/go/ir.(*Package).build(0xc00f2ee090)
        /home/firelizzard/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:2568 +0xac6
sync.(*Once).doSlow(0xc008ac42a0?, 0xc00165a5a0?)
        /usr/lib/go/src/sync/once.go:68 +0xc2
sync.(*Once).Do(...)
        /usr/lib/go/src/sync/once.go:59
honnef.co/go/tools/go/ir.(*Package).Build(...)
        /home/firelizzard/go/pkg/mod/honnef.co/go/tools@v0.3.1/go/ir/builder.go:2505
honnef.co/go/tools/internal/passes/buildir.run(0xc020d02dd0)
        /home/firelizzard/go/pkg/mod/honnef.co/go/tools@v0.3.1/internal/passes/buildir/buildir.go:86 +0x368
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc0027ad240)
        /home/firelizzard/go/pkg/mod/github.com/golangci/golangci-lint@v1.46.2/pkg/golinters/goanalysis/runner_action.go:187 +0x9c4
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
        /home/firelizzard/go/pkg/mod/github.com/golangci/golangci-lint@v1.46.2/pkg/golinters/goanalysis/runner_action.go:105 +0x1d
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc001487b80, {0x159a919, 0x7}, 0xc0021cdf48)
        /home/firelizzard/go/pkg/mod/github.com/golangci/golangci-lint@v1.46.2/pkg/timeutils/stopwatch.go:111 +0x4a
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc000bc7ce0?)
        /home/firelizzard/go/pkg/mod/github.com/golangci/golangci-lint@v1.46.2/pkg/golinters/goanalysis/runner_action.go:104 +0x85
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc0027ad240)
        /home/firelizzard/go/pkg/mod/github.com/golangci/golangci-lint@v1.46.2/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xb4
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze
        /home/firelizzard/go/pkg/mod/github.com/golangci/golangci-lint@v1.46.2/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x1eb 
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: buildir: package "record" (isInitialPkg: true, needAnalyzeSource: true): in gitlab.com/accumulatenetwork/accumulate/internal/database/record.init: cannot convert gitlab.com/accumulatenetwork/accumulate/internal/database/record.copyValue (func[T any](v T) T) to func(uint64) uint64 
WARN [linters context] structcheck is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
ERRO Running error: 1 error occurred:
        * can't run linter goanalysis_metalinter: goanalysis_metalinter: buildir: package "record" (isInitialPkg: true, needAnalyzeSource: true): in gitlab.com/accumulatenetwork/accumulate/internal/database/record.init: cannot convert gitlab.com/accumulatenetwork/accumulate/internal/database/record.copyValue (func[T any](v T) T) to func(uint64) uint64
urso commented 2 years ago

Another example:

package main

import "fmt"

func printGeneric[T any](v T) {
        fmt.Println(v)
}

func unused() {}

func main() {
        printInt := printGeneric[int] // This line seems to produce the panic in the linter

        printInt(1)
}

In some cases I managed to workaround the issue by wrapping the instantiation into a function. For example:

package main

import "fmt"

func printGeneric[T any](v T) {
        fmt.Println(v)
}

func unused() {}

func main() {
        // printInt := printGeneric[int]
        printInt := func(v int) {
                printGeneric(v)
        }

        printInt(1)
}

In this case the gosimple linter might complain about not using a "lambda", but at least no panic.

firelizzard18 commented 2 years ago

I've tracked this down to the fact that go/types.Info.Instances is nil. In my example above, when I run upstream staticcheck, on this line fn.Pkg.info.Instances has an entry for copyValue and thus makeInstance is called, which constructs and returns an instantiated generic function, which then succeeds later.

However when running within golangci-lint, that map is nil, so expr0 instead returns the uninstantiated generic function, which fails.

firelizzard18 commented 2 years ago
diff --git a/pkg/golinters/goanalysis/runner_loadingpackage.go b/pkg/golinters/goanalysis/runner_loadingpackage.go
index 1ac6b83e..a5b5cccf 100644
--- a/pkg/golinters/goanalysis/runner_loadingpackage.go
+++ b/pkg/golinters/goanalysis/runner_loadingpackage.go
@@ -123,6 +123,7 @@ func (lp *loadingPackage) loadFromSource(loadMode LoadMode) error {

        pkg.TypesInfo = &types.Info{
                Types:      make(map[ast.Expr]types.TypeAndValue),
+               Instances:  make(map[*ast.Ident]types.Instance),
                Defs:       make(map[*ast.Ident]types.Object),
                Uses:       make(map[*ast.Ident]types.Object),
                Implicits:  make(map[ast.Node]types.Object),
firelizzard18 commented 2 years ago

You can use my patch by adding replace github.com/golangci/golangci-lint v1.46.2 => github.com/firelizzard18/golangci-lint v1.46.3-0.20220713213035-328ba3e7213d to your go.mod.