golangci / golangci-lint

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

gocritic rangeValCopy check panics on generics #3485

Closed ryancurrah closed 1 year ago

ryancurrah commented 1 year ago

Welcome

Description of the problem

When linting code that contains generics with gocritic rangeValCopy check golangci-lint panics. I suggest we add gocritic back to the disabled list of linters due to not fully working with generics.

Version of golangci-lint

```console $ golangci-lint --version ╰─ golangci-lint --version golangci-lint has version 1.50.1 built from 8926a95 on 2022-10-22T10:48:48Z ```

Configuration file

```console $ cat .golangci.yml # options for analysis running run: modules-download-mode: readonly deadline: 10m timeout: 10m issues-exit-code: 0 tests: true skip-files: - "mock_.*\\.go" - "generated.*\\.go" - ".*\\.gen\\.go" - ".*_gen\\.go" - ".*\\.pb\\.go" # output configuration options output: format: tab print-issued-lines: false print-linter-name: true uniq-by-line: false # all available settings of specific linters linters-settings: gocritic: disabled-checks: - regexpMust - hugeParam - commentFormatting enabled-tags: - performance settings: captLocal: paramsOnly: true rangeValCopy: sizeThreshold: 1024 # 1Kb linters: disable-all: true enable: - gocritic fast: false issues: max-issues-per-linter: 0 max-same-issues: 0 exclude-use-default: false exclude: # shadown frequently triggers on err, so exclude, see https://groups.google.com/g/golang-nuts/c/ObtoxsN7AWg - 'declaration of "err" shadows declaration at' exclude-rules: # ease some gocritic warnings on test files - path: _test\.go text: "(unnamedResult|exitAfterDefer)" linters: - gocritic ```

Go environment

```console $ go version && go env go version go1.18.10 darwin/amd64 GO111MODULE="auto" GOARCH="amd64" GOBIN="" GOCACHE="/Users/rcurrah/Library/Caches/go-build" GOENV="/Users/rcurrah/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/rcurrah/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/rcurrah/go" GOPRIVATE="" GOPROXY="" GOROOT="/Users/rcurrah/.go/current" GOSUMDB="" GOTMPDIR="" GOTOOLDIR="/Users/rcurrah/.go/current/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.18.10" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="" GOWORK="" CGO_CFLAGS="-O0 -g -I/usr/local/include/zookeeper" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/34/n05pjx4x7n3_cv9qt_3qqdpw0000gn/T/go-build3581913089=/tmp/go-build -gno-record-gcc-switches -fno-common" ```

Verbose output of running

```console $ golangci-lint cache clean $ golangci-lint run -v INFO [config_reader] Config search paths: [./ /Users/rcurrah/go.crwd.dev/ce/workflow /Users/rcurrah/go.crwd.dev/ce /Users/rcurrah/go.crwd.dev /Users/rcurrah /Users /] INFO [config_reader] Used config file .golangci.yml INFO [lintersdb] Active 1 linters: [gocritic] INFO [loader] Go packages loading at mode 575 (files|imports|name|compiled_files|deps|exports_file|types_sizes) took 6.045652889s INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 84.985912ms INFO [linters_context/goanalysis] analyzers took 3m38.78025894s with top 10 stages: gocritic: 3m38.78025894s ERRO [runner] Panic: gocritic: package "cache" (isInitialPkg: true, needAnalyzeSource: true): go/types/sizes.go:82: assertion failed: goroutine 40525 [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:102 +0x155 panic({0x100c61960, 0xc035e820e0}) runtime/panic.go:884 +0x212 go/types.assert(0xa8?) go/types/errors.go:27 +0x5b go/types.(*StdSizes).Alignof(0xc00004d240, {0x1010b0fa8?, 0xc016f86b10}) go/types/sizes.go:82 +0x1b6 go/types.(*StdSizes).Offsetsof(0x1010b0e18?, {0xc00d959ea0, 0x2, 0x0?}) go/types/sizes.go:123 +0xdc go/types.(*StdSizes).Sizeof(0xc00004d240, {0x1010b0e18?, 0xc04476d030}) go/types/sizes.go:176 +0x285 github.com/go-critic/go-critic/framework/linter.(*CheckerContext).SizeOf(...) github.com/go-critic/go-critic@v0.6.5/framework/linter/linter.go:325 github.com/go-critic/go-critic/checkers.(*rangeValCopyChecker).VisitStmt(0xc033add220, {0x1010b44b8?, 0xc01779b860?}) github.com/go-critic/go-critic@v0.6.5/checkers/rangeValCopy_checker.go:72 +0xc9 github.com/go-critic/go-critic/checkers/internal/astwalk.(*stmtWalker).WalkFile.func1({0x1010b0a30?, 0xc01779b860?}) github.com/go-critic/go-critic@v0.6.5/checkers/internal/astwalk/stmt_walker.go:23 +0x62 go/ast.inspector.Visit(0xc035e820b0, {0x1010b0a30?, 0xc01779b860?}) go/ast/walk.go:386 +0x31 go/ast.Walk({0x1010adb00?, 0xc035e820b0?}, {0x1010b0a30?, 0xc01779b860?}) go/ast/walk.go:51 +0x62 go/ast.walkStmtList({0x1010adb00, 0xc035e820b0}, {0xc00d853d80?, 0x6, 0x40?}) go/ast/walk.go:32 +0x91 go/ast.Walk({0x1010adb00?, 0xc035e820b0?}, {0x1010b03c8?, 0xc039b7adb0?}) go/ast/walk.go:234 +0x606 go/ast.Inspect(...) go/ast/walk.go:397 github.com/go-critic/go-critic/checkers/internal/astwalk.(*stmtWalker).WalkFile(0xc034bb61e0?, 0xc00d853e80?) github.com/go-critic/go-critic@v0.6.5/checkers/internal/astwalk/stmt_walker.go:21 +0x12c github.com/go-critic/go-critic/framework/linter.(*Checker).Check(...) github.com/go-critic/go-critic@v0.6.5/framework/linter/linter.go:130 github.com/golangci/golangci-lint/pkg/golinters.runGocriticOnFile(0xc02995d980, 0xc0053a70ca?, {0xc034bd0600, 0x2b, 0x100cd3c00?}) github.com/golangci/golangci-lint/pkg/golinters/gocritic.go:175 +0xd1 github.com/golangci/golangci-lint/pkg/golinters.runGocriticOnPackage(0xc02995d980, {0xc034bd0600, 0x2b, 0x40}, {0xc0014ee230, 0x9, 0x0?}) github.com/golangci/golangci-lint/pkg/golinters/gocritic.go:163 +0x1df github.com/golangci/golangci-lint/pkg/golinters.(*goCriticWrapper).run(0xc000c71a10, 0xc00e26c9c0) github.com/golangci/golangci-lint/pkg/golinters/gocritic.go:123 +0x217 github.com/golangci/golangci-lint/pkg/golinters.NewGoCritic.func1(0x100ccb7a0?) github.com/golangci/golangci-lint/pkg/golinters/gocritic.go:46 +0x39 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc00039a040) github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:188 +0x9d6 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2() github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:106 +0x1d github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc00211c500, {0x100e3a6b1, 0x8}, 0xc004480748) github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x4a github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc023a66d80?) github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:105 +0x85 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc00039a040) 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 gocritic: gocritic: gocritic: package "cache" (isInitialPkg: true, needAnalyzeSource: true): go/types/sizes.go:82: assertion failed INFO [runner] processing took 213.886µs with stages: nolint: 204.734µs, max_same_issues: 4.928µs, skip_dirs: 902ns, cgo: 888ns, max_from_linter: 401ns, uniq_by_line: 192ns, source_code: 182ns, path_prettifier: 171ns, filename_unadjuster: 168ns, identifier_marker: 162ns, diff: 159ns, path_shortener: 159ns, skip_files: 147ns, exclude: 130ns, autogenerated_exclude: 128ns, max_per_file_from_linter: 108ns, sort_results: 93ns, severity-rules: 87ns, path_prefixer: 81ns, exclude-rules: 66ns INFO [runner] linters took 23.233541984s with stages: gocritic: 23.232871542s ERRO Running error: 1 error occurred: * can't run linter gocritic: gocritic: gocritic: package "cache" (isInitialPkg: true, needAnalyzeSource: true): go/types/sizes.go:82: assertion failed INFO Memory: 285 samples, avg is 856.9MB, max is 1470.5MB INFO Execution took 29.386214305s ```

Code example or link to a public repository

```go ```
boring-cyborg[bot] commented 1 year ago

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

ryancurrah commented 1 year ago

Created an issue on gocritic linter https://github.com/go-critic/go-critic/issues/1297

ldez commented 1 year ago

Issue #2649 already handles bugs around generics. As an issue is open in the go-critic repo, we don't need to keep this one.

ryancurrah commented 1 year ago

Sorry @ldez this issue was to add gocritic to the list of linters that do not support generics. IE disabled by default for go 1.18 or greater.

ldez commented 1 year ago

we don't disable go-critic when only a few rules have a problem.

ryancurrah commented 1 year ago

I see thank you for the input.