Skip to content

unused doesn't work with "exported-is-used" and "exported-fields-are-used" linter settings #4218

Closed
@pietdevries94

Description

@pietdevries94

Welcome

Description of the problem

When using unused with either "exported-is-used" or "exported-fields-are-used" linter settings or both, golangci-lint panics.

I have both tried in go 1.20 and 1.21

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.55.2 built with go1.21.3 from e3c2265f on 2023-11-03T12:59:25Z

Configuration

linters:
  enable:
    - unused
linters-settings:
  unused:
    exported-is-used: false
    exported-fields-are-used: false

Go environment

$ go version && go env
go version go1.20.8 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/piet/.cache/go-build"
GOENV="/home/piet/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/piet/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/piet/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/nix/store/cbfw4zvybzvhvqb14a14pwpsvcnnpjcg-go-1.20.8/share/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/nix/store/cbfw4zvybzvhvqb14a14pwpsvcnnpjcg-go-1.20.8/share/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.8"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/tmp.PJ3iHlw0ZJ/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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/run/user/1000/go-build3312085719=/tmp/go-build -gno-record-gcc-switches"

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /tmp/tmp.PJ3iHlw0ZJ /tmp / /home/piet] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 6 linters: [errcheck gosimple govet ineffassign staticcheck unused] 
INFO [loader] Go packages loading at mode 575 (exports_file|types_sizes|compiled_files|deps|files|imports|name) took 49.598673ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 94.55µs 
INFO [linters_context/goanalysis] analyzers took 779.556298ms with top 10 stages: buildir: 616.212553ms, inspect: 37.842009ms, SA5012: 22.853563ms, printf: 20.040602ms, ctrlflow: 19.631335ms, fact_deprecated: 18.408188ms, fact_purity: 16.0611ms, nilness: 12.353816ms, typedness: 10.489409ms, S1005: 190.001µs 
ERRO [runner] Panic: unused: package "something" (isInitialPkg: true, needAnalyzeSource: true): object "string" has no path but also no column information: goroutine 386 [running]:
runtime/debug.Stack()
        runtime/debug/stack.go:24 +0x5e
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:109 +0x27c
panic({0xf8a380?, 0xc0009cc330?})
        runtime/panic.go:914 +0x21f
honnef.co/go/tools/unused.(*SerializedGraph).Merge(0xc001489680, {0xc0001c0a80, 0x4, 0xc0001b5308?})
        honnef.co/go/[email protected]/unused/serialize.go:52 +0xdde
github.com/golangci/golangci-lint/pkg/golinters.getUnusedResults(0xc000f5e5b0, 0x2070696b7320646c?)
        github.com/golangci/golangci-lint/pkg/golinters/unused.go:110 +0x1f6
github.com/golangci/golangci-lint/pkg/golinters.runUnused(0xc000f5e5b0, 0xc0007e8b78?)
        github.com/golangci/golangci-lint/pkg/golinters/unused.go:56 +0x2a
github.com/golangci/golangci-lint/pkg/golinters.NewUnused.func1(0xfd94e0?)
        github.com/golangci/golangci-lint/pkg/golinters/unused.go:30 +0x2d
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc000ea4db0)
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:195 +0x9d6
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:113 +0x17
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc0014108c0, {0x112dc5e, 0x6}, 0xc000f88748)
        github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x44
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0x7d0a7d7b65756575?)
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:112 +0x7a
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc000ea4db0)
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xa8
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze in goroutine 142
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x205 
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: unused: package "something" (isInitialPkg: true, needAnalyzeSource: true): object "string" has no path but also no column information 
INFO [runner] processing took 2.764µs with stages: skip_dirs: 531ns, max_same_issues: 521ns, nolint: 201ns, autogenerated_exclude: 150ns, cgo: 140ns, path_prettifier: 130ns, filename_unadjuster: 130ns, max_from_linter: 130ns, skip_files: 121ns, identifier_marker: 120ns, source_code: 120ns, fixer: 110ns, diff: 50ns, exclude-rules: 50ns, path_shortener: 40ns, path_prefixer: 40ns, sort_results: 40ns, severity-rules: 40ns, exclude: 40ns, uniq_by_line: 30ns, max_per_file_from_linter: 30ns 
INFO [runner] linters took 678.204076ms with stages: goanalysis_metalinter: 678.174341ms 
ERRO Running error: 1 error occurred:
        * can't run linter goanalysis_metalinter: goanalysis_metalinter: unused: package "something" (isInitialPkg: true, needAnalyzeSource: true): object "string" has no path but also no column information
 
INFO Memory: 9 samples, avg is 154.4MB, max is 232.3MB 
INFO Execution took 733.799125ms

A minimal reproducible example or link to a public repository

https://github.com/pietdevries94/golangci-lint-unused-reproduction

Validation

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions