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

Panic when instantiating a generic function #2940

Closed
4 tasks done
urso opened this issue Jun 21, 2022 · 2 comments
Closed
4 tasks done

Panic when instantiating a generic function #2940

urso opened this issue Jun 21, 2022 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@urso
Copy link

urso commented Jun 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

When instantiating a generic function into a local variable like myvar := mygenericfunc[int] golangci-lint produces a panic.

The sample code given reproduces the problem. The sample code includes an unused function that shall be flagged by the linter.

It seems the staticcheck based linters like ununsed, gosimple, staticcheck are affected.

Testing the sample code with staticcheck works for me:

$ staticcheck -version
staticcheck 2022.1 (v0.3.0)
$ staticcheck -checks U1000,S1029 .
main.go:9:6: func unused is unused (U1000)

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.46.2 built from a3336890 on 2022-05-17T11:31:29Z

Note: building golangci-lint master branch fails as well

Configuration file

$ cat .golangci.yml
cat: .golangci.yml: No such file or directory

Go environment

$ go version && go env
go version go1.18.3 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/urso/.cache/go-build"
GOENV="/home/urso/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/urso/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/urso/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/urso/.asdf/installs/golang/1.18.3/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/urso/.asdf/installs/golang/1.18.3/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/urso/workspace/src/github.com/urso/checkerr/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-build254684928=/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: [./ /home/urso/workspace/src/github.com/urso/checkerr /home/urso/workspace/src/github.com/urso /home/urso/workspace/src/github.com /home/urso/workspace/src /home/urso/workspace /home/urso /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|name|compiled_files|exports_file|types_sizes|deps) took 206.946885ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 120.849µs
INFO [linters context/goanalysis] analyzers took 1.308125511s with top 10 stages: buildir: 851.821139ms, fact_purity: 85.363223ms, ctrlflow: 73.018183ms, nilness: 65.477231ms, printf: 63.824508ms, inspect: 62.209949ms, fact_deprecated: 42.903237ms, SA5012: 28.541561ms, typedness: 23.689558ms, S1020: 414.867µs
ERRO [runner] Panic: S1029: package "main" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: interface {} is nil, not *buildir.IR: goroutine 1377 [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({0xf00a80, 0xc008ea8ff0})
        runtime/panic.go:838 +0x207
honnef.co/go/tools/internal/sharedcheck.CheckRangeStringRunes(0xc00115a5b0)
        honnef.co/go/tools@v0.3.1/internal/sharedcheck/lint.go:24 +0x17b
honnef.co/go/tools/simple.CheckRangeStringRunes(0xee2aa0?)
        honnef.co/go/tools@v0.3.1/simple/lint.go:1630 +0x19
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc0015b4010)
        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(0xc0004956d0, {0x10130c8, 0x5}, 0xc000cde748)
        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(0xc0015b4010)
        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: S1029: package "main" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: interface {} is nil, not *buildir.IR
WARN [linters context] structcheck is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649.
INFO [runner] processing took 3.699µs with stages: max_same_issues: 999ns, nolint: 330ns, max_from_linter: 290ns, skip_dirs: 280ns, cgo: 260ns, skip_files: 200ns, autogenerated_exclude: 160ns, path_prettifier: 160ns, filename_unadjuster: 160ns, exclude: 150ns, source_code: 80ns, sort_results: 70ns, diff: 70ns, severity-rules: 70ns, max_per_file_from_linter: 70ns, uniq_by_line: 70ns, exclude-rules: 70ns, path_prefixer: 70ns, identifier_marker: 70ns, path_shortener: 70ns
INFO [runner] linters took 1.013487199s with stages: goanalysis_metalinter: 1.01342836s, structcheck: 11.27µs
ERRO Running error: 1 error occurred:
        * can't run linter goanalysis_metalinter: goanalysis_metalinter: S1029: package "main" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: interface {} is nil, not *buildir.IR

INFO Memory: 14 samples, avg is 145.6MB, max is 223.0MB
INFO Execution took 1.296626962s

Code example or link to a public repository

package main

import "fmt"

func printGeneric[T any](v T) {
        fmt.Println(v)
}

func unused() {}

func main() {
        printInt := printGeneric[int] // This line seems to produce the panic in the linter

        printInt(1)
}
@urso urso added the bug Something isn't working label Jun 21, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Jun 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 Jun 21, 2022

duplicate of #2859

@ldez ldez closed this as completed Jun 21, 2022
@ldez ldez added duplicate This issue or pull request already exists and removed bug Something isn't working labels Jun 21, 2022
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
Projects
None yet
Development

No branches or pull requests

2 participants