golangci / golangci-lint

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

shift: package "util": invalid memory address or nil pointer dereference #4793

Closed longhopefor closed 4 weeks ago

longhopefor commented 4 weeks ago

Welcome

Description of the problem

ERRO [runner] Panic: shift: package "util" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference: goroutine 52044 [running]:
runtime/debug.Stack()
        /Users/wanglong/.cache/pre-commit/repo72olrahy/golangenv-default/.go/src/runtime/debug/stack.go:24 +0x64
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
        /Users/wanglong/.cache/pre-commit/repo72olrahy/pkg/golinters/goanalysis/runner_action.go:109 +0x21c
panic({0x10330f460?, 0x103cd81d0?})
        /Users/wanglong/.cache/pre-commit/repo72olrahy/golangenv-default/.go/src/runtime/panic.go:770 +0x124
go/types.(*StdSizes).Sizeof(0x0, {0x103477260, 0x103ceff00})
        /Users/wanglong/.cache/pre-commit/repo72olrahy/golangenv-default/.go/src/go/types/sizes.go:228 +0x314
golang.org/x/tools/go/analysis/passes/shift.checkLongShift(0x140256aed00, {0x103476928, 0x140133e9440}, {0x10347a7a8, 0x1401c4fbaa0}, {0x10347b348, 0x1401c4fbac0})
        /Users/wanglong/.cache/pre-commit/repo72olrahy/golangenv-default/pkg/mod/golang.org/x/tools@v0.12.0/go/analysis/passes/shift/shift.go:115 +0x218
golang.org/x/tools/go/analysis/passes/shift.run.func2({0x103476928, 0x140133e9440})
        /Users/wanglong/.cache/pre-commit/repo72olrahy/golangenv-default/pkg/mod/golang.org/x/tools@v0.12.0/go/analysis/passes/shift/shift.go:64 +0x11c
golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0x1402464b1a0, {0x1400339acb0?, 0x103d042c0?, 0x102467a54?}, 0x140092f9cf0)
        /Users/wanglong/.cache/pre-commit/repo72olrahy/golangenv-default/pkg/mod/golang.org/x/tools@v0.12.0/go/ast/inspector/inspector.go:82 +0x90
golang.org/x/tools/go/analysis/passes/shift.run(0x140256aed00)
        /Users/wanglong/.cache/pre-commit/repo72olrahy/golangenv-default/pkg/mod/golang.org/x/tools@v0.12.0/go/analysis/passes/shift/shift.go:55 +0x110
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0x14005e85140)
        /Users/wanglong/.cache/pre-commit/repo72olrahy/pkg/golinters/goanalysis/runner_action.go:195 +0x8a4
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
        /Users/wanglong/.cache/pre-commit/repo72olrahy/pkg/golinters/goanalysis/runner_action.go:113 +0x20
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0x14002d89040, {0x102f44eca, 0x5}, 0x14003833f30)
        /Users/wanglong/.cache/pre-commit/repo72olrahy/pkg/timeutils/stopwatch.go:111 +0x44
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0x10293a090?)
        /Users/wanglong/.cache/pre-commit/repo72olrahy/pkg/golinters/goanalysis/runner_action.go:112 +0x78
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0x14005e85140)
        /Users/wanglong/.cache/pre-commit/repo72olrahy/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xb0
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze in goroutine 1231
        /Users/wanglong/.cache/pre-commit/repo72olrahy/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x184 
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: shift: package "util" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference 
ERRO Running error: 1 error occurred:
        * can't run linter goanalysis_metalinter: goanalysis_metalinter: shift: package "util" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference

Version of golangci-lint

```console $ golangci-lint --version golangci-lint has version v1.54.2 built with go1.20.14 from (unknown, mod sum: "h1:oR9zxfWYxt7hFqk6+fw6Enr+E7F0SN2nqHhJYyIb0yo=") on (unknown) ```

Configuration

```yml run: # timeout for analysis, e.g. 30s, 5m, default is 1m timeout: 10m issues-exit-code: 1 tests: false modules-download-mode: vendor # output configuration options output: path-prefix: "" sort-results: true print-issued-lines: false print-linter-name: true uniq-by-line: false linters: disable-all: true enable: - unused - errcheck - gosimple - govet - ineffassign - staticcheck - bodyclose - prealloc - dupl - exportloopref - funlen - gocognit - goconst - gocritic - funlen - gocognit - gocyclo - stylecheck - unconvert - whitespace issues: exclude-dirs: - pkg/cticker - app/snakesocial/config/configtest - pkg/push/pushtest - vendor exclude-files: - pkg/cticker/cticker.go new: true new-from-rev: "HEAD~1" whole-files: false ```

Go environment

```console $ go version && go env go version go1.20.14 darwin/arm64 GO111MODULE="on" GOARCH="arm64" GOBIN="" GOCACHE="/usr/local/Library/Caches/go-build" GOENV="/usr/local/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/usr/local/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="//usr/local/go" GOPRIVATE="" GOPROXY="https://goproxy.cn,direct" GOROOT="/usr/local/go/go1.20.14" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/go1.20.14/pkg/tool/darwin_arm64" GOVCS="" GOVERSION="go1.20.14" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/usr/local/go/modsrc/web/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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/95/fl7qk2yx1cz2y2tzfyz55bqh0000gn/T/go-build2242698392=/tmp/go-build -gno-record-gcc-switches -fno-common" ```

Verbose output of running

```console $ golangci-lint cache clean $ golangci-lint run -v ERRO [runner] Panic: shift: package "util" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference: goroutine 52044 [running]: runtime/debug.Stack() /Users/wanglong/.cache/pre-commit/repo72olrahy/golangenv-default/.go/src/runtime/debug/stack.go:24 +0x64 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1() /Users/wanglong/.cache/pre-commit/repo72olrahy/pkg/golinters/goanalysis/runner_action.go:109 +0x21c panic({0x10330f460?, 0x103cd81d0?}) /Users/wanglong/.cache/pre-commit/repo72olrahy/golangenv-default/.go/src/runtime/panic.go:770 +0x124 go/types.(*StdSizes).Sizeof(0x0, {0x103477260, 0x103ceff00}) /Users/wanglong/.cache/pre-commit/repo72olrahy/golangenv-default/.go/src/go/types/sizes.go:228 +0x314 golang.org/x/tools/go/analysis/passes/shift.checkLongShift(0x140256aed00, {0x103476928, 0x140133e9440}, {0x10347a7a8, 0x1401c4fbaa0}, {0x10347b348, 0x1401c4fbac0}) /Users/wanglong/.cache/pre-commit/repo72olrahy/golangenv-default/pkg/mod/golang.org/x/tools@v0.12.0/go/analysis/passes/shift/shift.go:115 +0x218 golang.org/x/tools/go/analysis/passes/shift.run.func2({0x103476928, 0x140133e9440}) /Users/wanglong/.cache/pre-commit/repo72olrahy/golangenv-default/pkg/mod/golang.org/x/tools@v0.12.0/go/analysis/passes/shift/shift.go:64 +0x11c golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0x1402464b1a0, {0x1400339acb0?, 0x103d042c0?, 0x102467a54?}, 0x140092f9cf0) /Users/wanglong/.cache/pre-commit/repo72olrahy/golangenv-default/pkg/mod/golang.org/x/tools@v0.12.0/go/ast/inspector/inspector.go:82 +0x90 golang.org/x/tools/go/analysis/passes/shift.run(0x140256aed00) /Users/wanglong/.cache/pre-commit/repo72olrahy/golangenv-default/pkg/mod/golang.org/x/tools@v0.12.0/go/analysis/passes/shift/shift.go:55 +0x110 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0x14005e85140) /Users/wanglong/.cache/pre-commit/repo72olrahy/pkg/golinters/goanalysis/runner_action.go:195 +0x8a4 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2() /Users/wanglong/.cache/pre-commit/repo72olrahy/pkg/golinters/goanalysis/runner_action.go:113 +0x20 github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0x14002d89040, {0x102f44eca, 0x5}, 0x14003833f30) /Users/wanglong/.cache/pre-commit/repo72olrahy/pkg/timeutils/stopwatch.go:111 +0x44 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0x10293a090?) /Users/wanglong/.cache/pre-commit/repo72olrahy/pkg/golinters/goanalysis/runner_action.go:112 +0x78 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0x14005e85140) /Users/wanglong/.cache/pre-commit/repo72olrahy/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xb0 created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze in goroutine 1231 /Users/wanglong/.cache/pre-commit/repo72olrahy/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x184 WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: shift: package "util" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference ERRO Running error: 1 error occurred: * can't run linter goanalysis_metalinter: goanalysis_metalinter: shift: package "util" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference ```

A minimal reproducible example or link to a public repository

```go // add your code here ```

Validation

Supporter

boring-cyborg[bot] commented 4 weeks ago

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

ldez commented 4 weeks ago

Hello,

  • [X] Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.

You have checked this box, but you are using golangci-lint v1.54.1.

The 2 latest releases are v1.58.1 and v1.59.0.

You should update golangci-lint to v1.59.0.

Also Go1.20 is no longer supported by the Go team, so I recommend updating to, at least, go1.21.

longhopefor commented 4 weeks ago

i am using golangci-lint v1.54.1, i want to known the reason of the problem, if i don't want to update the version, how can i solve the problem?

ldez commented 4 weeks ago

As the checked box message explained, we don't support old versions of golangci-lint.

So update your golangci-lint version, at least, to v1.54.2.

If you want custom support, don't hesitate to pay for it:

longhopefor commented 4 weeks ago

ok, got it