Skip to content

Gocritic panics when using custom linter plugins #4940

Closed
@ilya-hontarau

Description

@ilya-hontarau

Welcome

  • Yes, I'm using a binary release within 2 latest releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've read the typecheck section of the FAQ.
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.).
  • I agree to follow this project's Code of Conduct

Description of the problem

When I build a custom linter and run it, I get a panic from the gocritic linter. I can't reproduce it with the official build or with the gocritic linter.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.60.2 built with go1.23.0 from f338f3e on 2024-08-20T20:01:24Z

Configuration

linters-settings:
  gocritic:
    enabled-tags:
      - diagnostic


linters:
  disable-all: true
  enable:
    - gocritic

Go environment

$ go version && go env
go version go1.23.0 darwin/arm64
GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/ilyahontarau/Library/Caches/go-build'
GOENV='/Users/ilyahontarau/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/ilyahontarau/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/ilyahontarau/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.23.0/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.23.0/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.0'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/ilyahontarau/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/ilyahontarau/go/src/github.com/ilya-hontarau/golangci-lint-gocritic-bug/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 -ffile-prefix-map=/var/folders/sz/wj50zjyj38d7hh_0tk5vg7b40000gn/T/go-build2606000645=/tmp/go-build -gno-record-gcc-switches -fno-common'

Verbose output of running

golangci-lint-gocritic-bug git:(main) ✗ golangci-lint custom -v
INFO Cloning golangci-lint repository             
INFO Adding plugin imports                        
INFO generated imports info /var/folders/sz/wj50zjyj38d7hh_0tk5vg7b40000gn/T/custom-gcl3426684233/golangci-lint/cmd/golangci-lint/plugins.go:
package main

import (
        _ "github.com/ilya-hontarau/golangci-lint-gocritic-bug"
)
 
INFO Adding replace directives                    
INFO run: go mod edit -replace github.com/ilya-hontarau/golangci-lint-gocritic-bug=/Users/ilyahontarau/go/src/github.com/ilya-hontarau/golangci-lint-gocritic-bug 
INFO Running go mod tidy                          
INFO Building golangci-lint binary                
INFO Moving golangci-lint binary         golangci-lint-gocritic-bug git:(main) ✗ ./golangci-lint run -v lint/... 
INFO golangci-lint has version v1.60.2-custom-gcl built with go1.23.0 from ? on 2024-08-22 13:56:11.990335 +0000 UTC 
INFO [config_reader] Config search paths: [./ /Users/ilyahontarau/go/src/github.com/ilya-hontarau/golangci-lint-gocritic-bug/lint /Users/ilyahontarau/go/src/github.com/ilya-hontarau/golangci-lint-gocritic-bug /Users/ilyahontarau/go/src/github.com/ilya-hontarau /Users/ilyahontarau/go/src/github.com /Users/ilyahontarau/go/src /Users/ilyahontarau/go /Users/ilyahontarau /Users /] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 1 linters: [gocritic]     
INFO [loader] Go packages loading at mode 575 (deps|exports_file|name|types_sizes|compiled_files|files|imports) took 19.867541ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 276.875µs 
INFO [linters_context/goanalysis] analyzers took 1.459µs with top 10 stages: typecheck: 1.459µs 
ERRO [runner] Panic: gocritic: package "lint" (isInitialPkg: true, needAnalyzeSource: true): unreachable: goroutine 663 [running]:
runtime/debug.Stack()
        /opt/homebrew/Cellar/go/1.23.0/libexec/src/runtime/debug/stack.go:26 +0x64
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe.func1()
        /var/folders/sz/wj50zjyj38d7hh_0tk5vg7b40000gn/T/custom-gcl383768832/golangci-lint/pkg/goanalysis/runner_action.go:109 +0x21c
panic({0x101ef4820?, 0x10211a9c0?})
        /opt/homebrew/Cellar/go/1.23.0/libexec/src/runtime/panic.go:785 +0x124
github.com/quasilyte/go-ruleguard/internal/xtypes.typeIdentical({0x10212b848?, 0x140002be0c0}, {0x10212b6b8?, 0x1400016c000?}, 0x0)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/internal/xtypes/xtypes.go:228 +0x570
github.com/quasilyte/go-ruleguard/internal/xtypes.Identical(...)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/internal/xtypes/xtypes.go:59
github.com/quasilyte/go-ruleguard/ruleguard/typematch.(*Pattern).matchIdentical(0x14002a88970, 0x14001ce0850, 0x14000a28990, {0x10212b848, 0x140002be0c0})
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/typematch/typematch.go:439 +0xc68
github.com/quasilyte/go-ruleguard/ruleguard/typematch.(*Pattern).MatchIdentical(0x14002a88970, 0x14001ce0850, {0x10212b848, 0x140002be0c0})
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/typematch/typematch.go:370 +0xb8
github.com/quasilyte/go-ruleguard/ruleguard.(*irLoader).newFilter.makeTypeIsFilter.func13(0x14001af1330)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/filters.go:351 +0x90
github.com/quasilyte/go-ruleguard/ruleguard.(*irLoader).newBinaryExprFilter.makeAndFilter.func1(0x14001af1330)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/filters.go:53 +0x34
github.com/quasilyte/go-ruleguard/ruleguard.(*rulesRunner).handleMatch(0x14001af1188, {0x14000cc2c60, 0x2c9, 0x14002a889a8, {0x101c3ffcb, 0x35}, {0x0, 0x0}, {0x0, 0x0}, ...}, ...)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/runner.go:382 +0xe0
github.com/quasilyte/go-ruleguard/ruleguard.(*rulesRunner).runRules.func1({{0x1021298f0, 0x140023ce580}, {0x140021eca00, 0x3, 0x8}})
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/runner.go:282 +0x90
github.com/quasilyte/gogrep.(*matcher).MatchNode(0x8?, 0x14001af11f8, {0x1021298f0, 0x140023ce580}, 0x14000052b88)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/gogrep@v0.5.0/match.go:113 +0x3d4
github.com/quasilyte/gogrep.(*Pattern).MatchNode(...)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/gogrep@v0.5.0/gogrep.go:94
github.com/quasilyte/go-ruleguard/ruleguard.(*rulesRunner).runRules(0x14001af1188, {0x1021298f0, 0x140023ce580}, 0x2)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/runner.go:281 +0x104
github.com/quasilyte/go-ruleguard/ruleguard.(*rulesRunner).run.func1({0x1021298f0?, 0x140023ce580?}, 0x14000052cd8?)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/runner.go:196 +0x38
github.com/quasilyte/go-ruleguard/ruleguard.(*astWalker).walk(0x140000535c8, {0x1021298f0?, 0x140023ce580})
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/ast_walker.go:194 +0x1f4
github.com/quasilyte/go-ruleguard/ruleguard.(*astWalker).walkStmtList(...)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/ast_walker.go:37
github.com/quasilyte/go-ruleguard/ruleguard.(*astWalker).walk(0x140000535c8, {0x102129508?, 0x1400116ca20})
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/ast_walker.go:218 +0x1968
github.com/quasilyte/go-ruleguard/ruleguard.(*astWalker).walk(0x140000535c8, {0x1021299b8?, 0x140023ce5c0})
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/ast_walker.go:240 +0x1748
github.com/quasilyte/go-ruleguard/ruleguard.(*astWalker).walkStmtList(...)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/ast_walker.go:37
github.com/quasilyte/go-ruleguard/ruleguard.(*astWalker).walk(0x140000535c8, {0x102129508?, 0x1400116ca50})
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/ast_walker.go:218 +0x1968
github.com/quasilyte/go-ruleguard/ruleguard.(*astWalker).walk(0x140000535c8, {0x102129ad0?, 0x1400224c780})
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/ast_walker.go:301 +0x27b8
github.com/quasilyte/go-ruleguard/ruleguard.(*astWalker).walkStmtList(...)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/ast_walker.go:37
github.com/quasilyte/go-ruleguard/ruleguard.(*astWalker).walk(0x140000535c8, {0x102129508?, 0x1400116ca80})
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/ast_walker.go:218 +0x1968
github.com/quasilyte/go-ruleguard/ruleguard.(*astWalker).walk(0x140000535c8, {0x102129bc0?, 0x1400116cab0})
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/ast_walker.go:360 +0x490
github.com/quasilyte/go-ruleguard/ruleguard.(*astWalker).walkDeclList(...)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/ast_walker.go:43
github.com/quasilyte/go-ruleguard/ruleguard.(*astWalker).walk(0x140000535c8, {0x102128818?, 0x140006fa320})
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/ast_walker.go:367 +0x29e4
github.com/quasilyte/go-ruleguard/ruleguard.(*astWalker).Walk(...)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/ast_walker.go:20
github.com/quasilyte/go-ruleguard/ruleguard.(*rulesRunner).run(0x14001af1188, 0x140006fa320)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/runner.go:195 +0x14c
github.com/quasilyte/go-ruleguard/ruleguard.(*engine).Run(0x109ccb988?, 0x140007c7a40?, 0x14000053698?, 0x140006fa320)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/engine.go:129 +0x44
github.com/quasilyte/go-ruleguard/ruleguard.(*Engine).Run(...)
        /Users/ilyahontarau/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.4.2/ruleguard/ruleguard.go:77
github.com/go-critic/go-critic/checkers.runRuleguardEngine(0x14001dd3188, 0x140006fa320, 0x140027f33f0, 0x140007c7a40)
        /Users/ilyahontarau/go/pkg/mod/github.com/go-critic/go-critic@v0.11.4/checkers/ruleguard_checker.go:301 +0xbc
github.com/go-critic/go-critic/checkers.(*embeddedRuleguardChecker).WalkFile(0x140027f3730, 0x140006fa320)
        /Users/ilyahontarau/go/pkg/mod/github.com/go-critic/go-critic@v0.11.4/checkers/embedded_rules.go:100 +0x100
github.com/go-critic/go-critic/linter.(*Checker).Check(...)
        /Users/ilyahontarau/go/pkg/mod/github.com/go-critic/go-critic@v0.11.4/linter/linter.go:160
github.com/golangci/golangci-lint/pkg/golinters/gocritic.runOnFile(0x1400224dd40, 0x140006fa320, {0x14000d1c800, 0x3a, 0x101fdf860?})
        /var/folders/sz/wj50zjyj38d7hh_0tk5vg7b40000gn/T/custom-gcl383768832/golangci-lint/pkg/golinters/gocritic/gocritic.go:235 +0x9c
github.com/golangci/golangci-lint/pkg/golinters/gocritic.runOnPackage(0x1400224dd40, {0x14000d1c800, 0x3a, 0x40}, {0x140007b0768, 0x1, 0x200?})
        /var/folders/sz/wj50zjyj38d7hh_0tk5vg7b40000gn/T/custom-gcl383768832/golangci-lint/pkg/golinters/gocritic/gocritic.go:223 +0x160
github.com/golangci/golangci-lint/pkg/golinters/gocritic.(*goCriticWrapper).run(0x14000ce2240, 0x140002029a0)
        /var/folders/sz/wj50zjyj38d7hh_0tk5vg7b40000gn/T/custom-gcl383768832/golangci-lint/pkg/golinters/gocritic/gocritic.go:130 +0x228
github.com/golangci/golangci-lint/pkg/golinters/gocritic.New.func1(0x101f83860?)
        /var/folders/sz/wj50zjyj38d7hh_0tk5vg7b40000gn/T/custom-gcl383768832/golangci-lint/pkg/golinters/gocritic/gocritic.go:48 +0x38
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyze(0x1400097a7e0)
        /var/folders/sz/wj50zjyj38d7hh_0tk5vg7b40000gn/T/custom-gcl383768832/golangci-lint/pkg/goanalysis/runner_action.go:191 +0x8ac
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe.func2()
        /var/folders/sz/wj50zjyj38d7hh_0tk5vg7b40000gn/T/custom-gcl383768832/golangci-lint/pkg/goanalysis/runner_action.go:113 +0x20
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0x140003d37c0, {0x101b647e3, 0x8}, 0x1400086df30)
        /var/folders/sz/wj50zjyj38d7hh_0tk5vg7b40000gn/T/custom-gcl383768832/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x44
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe(0x1014e1900?)
        /var/folders/sz/wj50zjyj38d7hh_0tk5vg7b40000gn/T/custom-gcl383768832/golangci-lint/pkg/goanalysis/runner_action.go:112 +0x70
github.com/golangci/golangci-lint/pkg/goanalysis.(*loadingPackage).analyze.func2(0x1400097a7e0)
        /var/folders/sz/wj50zjyj38d7hh_0tk5vg7b40000gn/T/custom-gcl383768832/golangci-lint/pkg/goanalysis/runner_loadingpackage.go:82 +0xac
created by github.com/golangci/golangci-lint/pkg/goanalysis.(*loadingPackage).analyze in goroutine 662
        /var/folders/sz/wj50zjyj38d7hh_0tk5vg7b40000gn/T/custom-gcl383768832/golangci-lint/pkg/goanalysis/runner_loadingpackage.go:77 +0x174 
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: gocritic: package "lint" (isInitialPkg: true, needAnalyzeSource: true): unreachable 
INFO [runner] processing took 1.081µs with stages: max_same_issues: 375ns, nolint: 125ns, severity-rules: 42ns, skip_files: 42ns, uniq_by_line: 42ns, autogenerated_exclude: 42ns, skip_dirs: 42ns, cgo: 42ns, fixer: 42ns, path_prettifier: 41ns, filename_unadjuster: 41ns, diff: 41ns, exclude-rules: 41ns, exclude: 41ns, invalid_issue: 41ns, path_shortener: 41ns, max_from_linter: 0s, sort_results: 0s, identifier_marker: 0s, path_prefixer: 0s, max_per_file_from_linter: 0s, source_code: 0s 
INFO [runner] linters took 256.888167ms with stages: goanalysis_metalinter: 256.8695ms 
ERRO Running error: can't run linter goanalysis_metalinter
goanalysis_metalinter: gocritic: package "lint" (isInitialPkg: true, needAnalyzeSource: true): unreachable 
INFO Memory: 4 samples, avg is 50.9MB, max is 60.2MB 
INFO Execution took 283.781542ms          

A minimal reproducible example or link to a public repository

https://github.com/ilya-hontarau/golangci-lint-gocritic-bug

Validation

  • Yes, I've included all information above (version, config, etc.).

Supporter

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinglinter: customAbout custom/private linters

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions