Closed
Description
When exportloopref is enabled, it panics when running it on http://github.com/storj/storj repository.
To reproduce the issue:
git clone http://github.com/storj/storj
cd storj
golangci-lint run --enable exportloopref ./...
There are two problems with it: first that it panics (obviously), and the second that it doesn't fail with an error code.
Currently this meant that the issue went unnoticed for a few days, because the linter seemed to be passing.
Version of golangci-lint
$ golangci-lint --version
golangci-lint has version 1.28.3 built from 6ab3138 on 2020-07-11T22:33:41Z
Config file
Using defaults with exportloopref
enabled.
golangci-lint run --enable exportloopref ./...
Go environment
$ go version && go env
go version go1.15beta1 windows/amd64
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=Z:\gocache
set GOENV=C:\Users\egone\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=F:\Go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=F:\Go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=Z:\Temp\go-build784414934=/tmp/go-build -gno-record-gcc-switches
Verbose output of running
$ golangci-lint cache clean
$ golangci-lint run -v
level=info msg="[config_reader] Config search paths: [./ s:\\core\\storj s:\\core s:\\]"
level=info msg="[lintersdb] Active 11 linters: [deadcode errcheck exportloopref gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]"
level=info msg="[loader] Go packages loading at mode 575 (types_sizes|compiled_files|imports|name|deps|exports_file|files) took 2.7852736s"
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 83.9885ms"
level=info msg="[linters context/goanalysis] analyzers took 3m36.110927s with top 10 stages: buildir: 1m31.5461847s, printf: 19.259171s, ctrlflow: 18.9749632s, fact_deprecated: 18.6755285s, fact_purity: 17.0988739s, ineffassign: 2.7500731s, inspect: 2.5489433s, deadcode: 1.2279576s, S1038: 1.1309583s, varcheck: 1.1180419s"
level=warning msg="[linters context] Panic: exportloopref: package \"overlay_test\" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference: goroutine 45258 [running]:\nruntime/debug.Stack(0x110089f, 0x3c, 0xc014a2b6c0)\n\t/opt/hostedtoolcache/go/1.14.4/x64/src/runtime/debug/stack.go:24 +0xa4\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1(0xc0039b48c0)\n\t/home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:508 +0x1bc\npanic(0xf1c380, 0x1a06f60)\n\t/opt/hostedtoolcache/go/1.14.4/x64/src/runtime/panic.go:969 +0x174\ngo/ast.(*Object).Pos(0x0, 0xc0226f7600)\n\t/opt/hostedtoolcache/go/1.14.4/x64/src/go/ast/scope.go:93 +0x3e\ngithub.com/kyoh86/exportloopref.(*Searcher).checkUnaryExpr(0xc0146dbc10, 0xc0226f7620, 0xc016ff8a00, 0x8, 0x20, 0xc016ff8a58, 0xc014a2bad0)\n\t/home/runner/go/pkg/mod/github.com/kyoh86/[email protected]/exportloopref.go:172 +0xc6\ngithub.com/kyoh86/exportloopref.(*Searcher).Check(0xc014a2bc10, 0x12887c0, 0xc0226f7620, 0xc016ff8a00, 0x8, 0x20, 0x8000, 0xc02eb51200)\n\t/home/runner/go/pkg/mod/github.com/kyoh86/[email protected]/exportloopref.go:71 +0xe2\ngithub.com/kyoh86/exportloopref.run.func1(0x12887c0, 0xc0226f7620, 0x1, 0xc016ff8a00, 0x8, 0x20, 0x1)\n\t/home/runner/go/pkg/mod/github.com/kyoh86/[email protected]/exportloopref.go:43 +0x7c\ngolang.org/x/tools/go/ast/inspector.(*Inspector).WithStack(0xc0162ceee0, 0xc014a2bc98, 0x5, 0x5, 0xc0146dbc20)\n\t/home/runner/go/pkg/mod/golang.org/x/[email protected]/go/ast/inspector/inspector.go:126 +0x146\ngithub.com/kyoh86/exportloopref.run(0xc01452f500, 0x26c2c2b59, 0x1b15440, 0xc03841d800, 0x2)\n\t/home/runner/go/pkg/mod/github.com/kyoh86/[email protected]/exportloopref.go:42 +0x25d\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc0039b48c0)\n\t/home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:590 +0xa2c\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()\n\t/home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:512 +0x31\ngithub.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc0029a0140, 0x10b5dfd, 0xd, 0xc014a2bf70)\n\t/home/runner/work/golangci-lint/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x57\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc0039b48c0)\n\t/home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:511 +0x98\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc002571ea0, 0xc0039b48c0)\n\t/home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:1059 +0x68\ncreated by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze\n\t/home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:1054 +0x30d\n"
level=info msg="[linters context/goanalysis] analyzers took 28.3088197s with top 10 stages: buildir: 18.5347603s, U1000: 9.7740594s"
level=info msg="[runner] Issues before processing: 478, after processing: 0"
level=info msg="[runner] Processors filtering stat (out/in): skip_files: 478/478, skip_dirs: 478/478, autogenerated_exclude: 0/478, cgo: 478/478, filename_unadjuster: 478/478, path_prettifier: 478/478"
level=info msg="[runner] processing took 2.0019ms with stages: autogenerated_exclude: 1.0022ms, path_prettifier: 999.7µs, exclude: 0s, path_prefixer: 0s, filename_unadjuster: 0s, skip_files: 0s, identifier_marker: 0s, max_from_linter: 0s, skip_dirs: 0s, nolint: 0s, max_per_file_from_linter: 0s, cgo: 0s, diff: 0s, severity-rules: 0s, uniq_by_line: 0s, max_same_issues: 0s, path_shortener: 0s, source_code: 0s, exclude-rules: 0s"
level=info msg="[runner] linters took 10.9991422s with stages: goanalysis_metalinter: 8.3741451s, unused: 2.621995s"
level=info msg="File cache stats: 0 entries of total size 0B"
level=info msg="Memory: 140 samples, avg is 876.5MB, max is 1749.4MB"
level=info msg="Execution took 13.9444089s"