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

goanalysis_metalinter panics for generic internal package #2675

Closed
4 tasks done
BooleanCat opened this issue Mar 21, 2022 · 9 comments
Closed
4 tasks done

goanalysis_metalinter panics for generic internal package #2675

BooleanCat opened this issue Mar 21, 2022 · 9 comments
Labels
duplicate This issue or pull request already exists question Further information is requested

Comments

@BooleanCat
Copy link

BooleanCat commented Mar 21, 2022

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).
  • Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)

Description of the problem

Using golangci-lint run on github.com/BooleanCat/go-functional@v0.6.0 causes a panic with can't run linter goanalysis_metalinter: goanalysis_metalinter: buildir: package "assert" (isInitialPkg: true, needAnalyzeSource: true): T

Version of golangci-lint

golangci-lint has version 1.45.0 built from 1f4c1ed on 2022-03-18T14:35:36Z

Configuration file

No configuration file.

Go environment

go version go1.18 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/tom/.cache/go-build"
GOENV="/home/tom/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/tom/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/tom/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/linuxbrew/.linuxbrew/Cellar/go/1.18/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/linuxbrew/.linuxbrew/Cellar/go/1.18/libexec/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc-5"
CXX="g++-5"
CGO_ENABLED="1"
GOMOD="/home/tom/workspace/go-functional/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 -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1747512551=/tmp/go-build -gno-record-gcc-switches"

Verbose output of running

go-functional on  main via 🐹 v1.18
❯ golangci-lint cache clean

go-functional on  main via 🐹 v1.18
❯ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /home/tom/workspace/go-functional /home/tom/workspace /home/tom /home /]
INFO [lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]
INFO [loader] Go packages loading at mode 575 (files|imports|compiled_files|deps|exports_file|types_sizes|name) took 102.794591ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 2.064331ms
INFO [linters context/goanalysis] analyzers took 1.790342082s with top 10 stages: buildir: 882.438536ms, inspect: 80.10901ms, fact_purity: 78.916084ms, nilness: 51.976695ms, fact_deprecated: 39.492546ms, ctrlflow: 36.976273ms, printf: 34.814299ms, SA5012: 29.734003ms, S1038: 26.053204ms, SA9001: 18.313678ms
ERRO [runner] Panic: buildir: package "assert" (isInitialPkg: true, needAnalyzeSource: true): T: goroutine 2503 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:24 +0x65
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:101 +0x155
panic({0x142ab00, 0xc005edd500})
	runtime/panic.go:838 +0x207
honnef.co/go/tools/go/ir.(*Program).needMethods(0xc0020f2c40, {0x16e2710?, 0xc005edd500?}, 0x0)
	honnef.co/go/tools@v0.2.2/go/ir/methods.go:237 +0x5b1
honnef.co/go/tools/go/ir.(*Program).needMethods(0xc0020f2c40, {0x16e2670?, 0xc0032da180?}, 0x0)
	honnef.co/go/tools@v0.2.2/go/ir/methods.go:196 +0x347
honnef.co/go/tools/go/ir.(*Program).needMethods(0xc0020f2c40, {0x16e26e8?, 0xc00239e270?}, 0x0)
	honnef.co/go/tools@v0.2.2/go/ir/methods.go:233 +0x708
honnef.co/go/tools/go/ir.(*Program).needMethods(0xc0020f2c40, {0x16e2648?, 0xc00425cd00?}, 0x0)
	honnef.co/go/tools@v0.2.2/go/ir/methods.go:209 +0x448
honnef.co/go/tools/go/ir.(*Program).needMethodsOf(0xc0020f2c40, {0x16e2648?, 0xc00425cd00?})
	honnef.co/go/tools@v0.2.2/go/ir/methods.go:145 +0x70
honnef.co/go/tools/go/ir.(*Package).build(0xc0031cfb90)
	honnef.co/go/tools@v0.2.2/go/ir/builder.go:2375 +0x111
sync.(*Once).doSlow(0xc0020f2c40?, 0xc0007a7180?)
	sync/once.go:68 +0xc2
sync.(*Once).Do(...)
	sync/once.go:59
honnef.co/go/tools/go/ir.(*Package).Build(...)
	honnef.co/go/tools@v0.2.2/go/ir/builder.go:2363
honnef.co/go/tools/internal/passes/buildir.run(0xc0009a8270)
	honnef.co/go/tools@v0.2.2/internal/passes/buildir/buildir.go:86 +0x368
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc001270ca0)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:187 +0x9c4
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:105 +0x1d
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc0006e5180, {0x148bf31, 0x7}, 0xc002c68f48)
	github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x4a
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0x0?)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:104 +0x85
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc001270ca0)
	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 +0x1eb
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: buildir: package "assert" (isInitialPkg: true, needAnalyzeSource: true): T
INFO [runner] processing took 3.107µs with stages: max_same_issues: 541ns, skip_dirs: 316ns, nolint: 274ns, cgo: 251ns, max_from_linter: 228ns, exclude: 187ns, autogenerated_exclude: 168ns, uniq_by_line: 145ns, skip_files: 145ns, filename_unadjuster: 141ns, path_prettifier: 140ns, max_per_file_from_linter: 128ns, exclude-rules: 61ns, diff: 60ns, path_shortener: 58ns, source_code: 55ns, sort_results: 54ns, identifier_marker: 52ns, path_prefixer: 52ns, severity-rules: 51ns
INFO [runner] linters took 1.016099767s with stages: goanalysis_metalinter: 1.016055393s
ERRO Running error: 1 error occurred:
	* can't run linter goanalysis_metalinter: goanalysis_metalinter: buildir: package "assert" (isInitialPkg: true, needAnalyzeSource: true): T

INFO Memory: 13 samples, avg is 165.8MB, max is 258.6MB
INFO Execution took 1.126868101s

Code example or link to a public repository

https://github.com/BooleanCat/go-functional

git clone github.com/BooleanCat/go-functional
cd go-functional
golangci-lint run
@BooleanCat BooleanCat added the bug Something isn't working label Mar 21, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Mar 21, 2022

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

@ldez
Copy link
Member

ldez commented Mar 21, 2022

Hello,

As I explained here and here, if you are using generics you have to set the following configuration:

run:
    go: 1.18

https://golangci-lint.run/usage/configuration/#run-configuration

@ldez ldez closed this as completed Mar 21, 2022
@ldez ldez added duplicate This issue or pull request already exists question Further information is requested and removed bug Something isn't working labels Mar 21, 2022
@BooleanCat
Copy link
Author

👍 what do you think about adding this config to the release notes for 1.45 or would you accept a PR to document this outside of issues?

@ldez
Copy link
Member

ldez commented Mar 21, 2022

I'm working on the autodetection of the Go version #2669

@joa
Copy link

joa commented Mar 22, 2022

@ldez thank you for your hard work and keeping your head up. I feel sorry for commenting on a closed issue when there's probably plenty of activity around this project right now.

I am still running into the issue as described by OP even though I set go: 1.18 - and according to the logs the flag is used and some linters are being disabled.

The panic does still exist and I'll try to provide you with a minimal example to reproduce.

$ golangci-lint version
golangci-lint has version v1.45.0 built from (unknown, mod sum: "h1:T2oCVkYoeckBxcNS6DTYiSXN2QcTNuAWaHyLGfqzMlU=") on (unknown)
$ golangci-lint run
level=warning msg="[runner] The linter 'golint' is deprecated (since v1.41.0) due to: The repository of the linter has been archived by the owner.  Replaced by revive."
level=warning msg="[runner] The linter 'interfacer' is deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner. "
level=warning msg="[linters context] bodyclose is disabled because of go1.18. If you are not using go1.18, you can set `go: go1.17` in the `run` section. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649."
level=error msg="[runner] Panic: buildssa: package \"eventbus\" (isInitialPkg: true, needAnalyzeSource: true): T: goroutine 4252 [running]:\nruntime/debug.Stack()\n\t/usr/local/go/src/runtime/debug/stack.go:24 +0x65\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()\n\t/go/pkg/mod/github.com/golangci/golangci-lint@v1.45.0/pkg/golinters/goanalysis/runner_action.go:101 +0x155\npanic({0x142bae0, 0xc0090fc750})\n\t/usr/local/go/src/runtime/panic.go:838 +0x207\ngolang.org/x/tools/go/ssa.(*Program).needMethods(0xc0029a1790, {0x16e36d0?, 0xc0090fc750?}, 0x0)\n\t/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/methods.go:237 +0x5b1\ngolang.org/x/tools/go/ssa.(*Program).needMethods(0xc0029a1790, {0x16e34c8?, 0xc00e1e3368?}, 0x0)\n\t/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/methods.go:199 +0x4e8\ngolang.org/x/tools/go/ssa.(*Program).needMethods(0xc0029a1790, {0x16e36a8?, 0xc00e1e3380?}, 0x0)\n\t/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/methods.go:233 +0x708\ngolang.org/x/tools/go/ssa.(*Program).needMethods(0xc0029a1790, {0x16e3568?, 0xc007672310?}, 0x0)\n\t/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/methods.go:182 +0x1ce\ngolang.org/x/tools/go/ssa.(*Program).needMethods(0xc0029a1790, {0x16e36a8?, 0xc00e1e2ee8?}, 0x0)\n\t/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/methods.go:233 +0x708\ngolang.org/x/tools/go/ssa.(*Program).needMethods(0xc0029a1790, {0x16e3608?, 0xc00a5be240?}, 0x0)\n\t/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/methods.go:210 +0x46a\ngolang.org/x/tools/go/ssa.(*Program).needMethodsOf(0xc0029a1790, {0x16e3608?, 0xc00a5be240?})\n\t/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/methods.go:145 +0x70\ngolang.org/x/tools/go/ssa.(*Package).build(0xc009558300)\n\t/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/builder.go:2284 +0x111\nsync.(*Once).doSlow(0xc0029a1790?, 0xc00421bf40?)\n\t/usr/local/go/src/sync/once.go:68 +0xc2\nsync.(*Once).Do(...)\n\t/usr/local/go/src/sync/once.go:59\ngolang.org/x/tools/go/ssa.(*Package).Build(...)\n\t/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/builder.go:2272\ngolang.org/x/tools/go/analysis/passes/buildssa.run(0xc0029a15f0)\n\t/go/pkg/mod/golang.org/x/tools@v0.1.10/go/analysis/passes/buildssa/buildssa.go:72 +0x2ee\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc0016ceeb0)\n\t/go/pkg/mod/github.com/golangci/golangci-lint@v1.45.0/pkg/golinters/goanalysis/runner_action.go:187 +0x9c4\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()\n\t/go/pkg/mod/github.com/golangci/golangci-lint@v1.45.0/pkg/golinters/goanalysis/runner_action.go:105 +0x1d\ngithub.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc00153e730, {0x149743f, 0x8}, 0xc001b64f48)\n\t/go/pkg/mod/github.com/golangci/golangci-lint@v1.45.0/pkg/timeutils/stopwatch.go:111 +0x4a\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc0003427e0?)\n\t/go/pkg/mod/github.com/golangci/golangci-lint@v1.45.0/pkg/golinters/goanalysis/runner_action.go:104 +0x85\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc0016ceeb0)\n\t/go/pkg/mod/github.com/golangci/golangci-lint@v1.45.0/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xb4\ncreated by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze\n\t/go/pkg/mod/github.com/golangci/golangci-lint@v1.45.0/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x1eb\n"
level=warning msg="[runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: buildssa: package \"eventbus\" (isInitialPkg: true, needAnalyzeSource: true): T"
level=warning msg="[linters context] gosimple is disabled because of go1.18. If you are not using go1.18, you can set `go: go1.17` in the `run` section. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649."
level=warning msg="[linters context] noctx is disabled because of go1.18. If you are not using go1.18, you can set `go: go1.17` in the `run` section. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649."
level=warning msg="[linters context] rowserrcheck is disabled because of go1.18. If you are not using go1.18, you can set `go: go1.17` in the `run` section. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649."
level=warning msg="[linters context] staticcheck is disabled because of go1.18. If you are not using go1.18, you can set `go: go1.17` in the `run` section. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649."
level=warning msg="[linters context] stylecheck is disabled because of go1.18. If you are not using go1.18, you can set `go: go1.17` in the `run` section. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649."
level=warning msg="[linters context] unparam is disabled because of go1.18. If you are not using go1.18, you can set `go: go1.17` in the `run` section. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649."
level=warning msg="[linters context] unused is disabled because of go1.18. If you are not using go1.18, you can set `go: go1.17` in the `run` section. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649."
level=error msg="Running error: 1 error occurred:\n\t* can't run linter goanalysis_metalinter: goanalysis_metalinter: buildssa: package \"eventbus\" (isInitialPkg: true, needAnalyzeSource: true): T\n\n"

Edit: The issue here is that I did have a .golangci.yml with linters like bodyclose being explicitly referenced in enable. I guess it would be worth mentioning that this can cause issues although you set the version to 1.18.

For reference I did add all the comments and it started to work, but it fails without the comments:

run:
  go: 1.18
  tests: true
  skip-files:
    - ".+_test.go"
    - "mock_.+"
  modules-download-mode: vendor
linters-settings:
  lll:
    line-length: 200
  dupl:
    threshold: 100
  goconst:
    min-len: 2
    min-occurrences: 2
  golint:
    min-confidence: 0.4
  misspell:
    locale: US
linters:
  disable-all: true
  enable:
    #- bodyclose
    - deadcode
    - depguard
    - dogsled
    - dupl
    - errcheck
    - exhaustive
    - goconst
    - gocritic
    - gocyclo
    - gofmt
    - goimports
    - revive
    - goprintffuncname
    - gosec
    #- gosimple
    - govet
    - ineffassign
    - lll
    - misspell
    #- noctx
    #- rowserrcheck
    - exportloopref
    #- staticcheck
    - structcheck
    #- stylecheck
    - typecheck
    - unconvert
    #- unparam
    #- unused
    - varcheck
    - whitespace
    - nolintlint

@ldez
Copy link
Member

ldez commented Mar 22, 2022

@joa can you open a new issue?

Edit: The issue here is that I did have a .golangci.yml with linters like bodyclose being explicitly referenced in enable. I guess it would be worth mentioning that this can cause issues although you set the version to 1.18.

With the new option, linters like bodyclose are not disabled but inactivated you don't have to remove them from the configuration.

@joa
Copy link

joa commented Mar 22, 2022

It seems to be more complicated. The output of my runner is at v1.45.0 (as shown) but my local machine was not. Hence it worked when I documented out bodyclose. I currently try to come up with a minimal example but fail to do so. CI fails, local works. golangci-lint reports the same version for both. I'll investigate but assume it's my environment that's misconfigured.

@joa
Copy link

joa commented Mar 22, 2022

@ldez The difference was that I still used golint in the CI version as the .golangci.yml is autogenerated and locally I changed this to revive. I also removed interfacer. That does the trick.

@NicklasWallgren
Copy link

I've also encountered this issue with 1.46.2 and run: go: 1.18

ERRO Running error: 1 error occurred:
        * can't run linter goanalysis_metalinter: goanalysis_metalinter: buildir: package "stream" (isInitialPkg: false, needAnalyzeSource: true): in github.com/mariomac/gostream/stream.Concat$1$1: cannot convert github.com/mariomac/gostream/stream.finishedIterator (func[T any]() (T, bool)) to github.com/mariomac/gostream/stream.iterator[T]

The golangci.yml can be found here, https://github.com/NicklasWallgren/go-template/blob/main/.golangci.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants