Skip to content

Panic on a valid go1.17 program with default configuration #2292

Closed
@tie

Description

@tie

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

Running golangci-lint run panics on a valid Go 1.17 program.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version v1.42.1 built from (unknown, mod sum: "h1:nC4WyrbdnNdohDVUoNKjy/4N4FTM1gCFaVeXecy6vzM=") on (unknown)

Configuration file

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

Go environment

$ go version && go env
go version go1.17.1 linux/amd64
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/tie/.cache/go-build"
GOENV="/home/tie/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS="-trimpath"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/tie/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/tie/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/tie/sdk/go1.17.1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/tie/sdk/go1.17.1/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.1"
GCCGO="gccgo"
AR="gcc-ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="0"
GOMOD="/home/tie/golangci-bug/go.mod"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3876884584=/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/tie/golangci-bug /home/tie /home /] 
INFO [lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck] 
INFO [loader] Go packages loading at mode 575 (types_sizes|deps|files|name|compiled_files|exports_file|imports) took 216.976234ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 675.357s 
INFO [linters context/goanalysis] analyzers took 8.782652969s with top 10 stages: buildir: 6.551375469s, inspect: 791.306542ms, ctrlflow: 328.862777ms, fact_deprecated: 256.954428ms, printf: 247.996752ms, SA5012: 176.742246ms, fact_purity: 164.969088ms, nilness: 140.291993ms, typedness: 121.880695ms, SA4008: 338.082s 
ERRO [runner] Panic: buildir: package "bug" (isInitialPkg: true, needAnalyzeSource: true): in bug.SecretFromBytes: cannot convert Load <[]byte> t0 ([]byte) to *bug.Secret: goroutine 2036 [running]:
runtime/debug.Stack()
        runtime/debug/stack.go:24 +0x65
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
        github.com/golangci/[email protected]/pkg/golinters/goanalysis/runner_action.go:101 +0x155
panic({0xdd1c80, 0xc0090b0e40})
        runtime/panic.go:1038 +0x215
honnef.co/go/tools/go/ir.emitConv(0xc004892900, {0x114e028, 0xc004327440}, {0x1129798, 0xc00b65a340}, {0x1128d70, 0xc00274f080})
        honnef.co/go/[email protected]/go/ir/emit.go:261 +0xb25
honnef.co/go/tools/go/ir.(*builder).expr0(0xc0058e7a40, 0xc004892900, {0x112c130, 0xc00274f080}, {0x7, {0x1129798, 0xc00b65a340}, {0x0, 0x0}})
        honnef.co/go/[email protected]/go/ir/builder.go:544 +0xa77
honnef.co/go/tools/go/ir.(*builder).expr(0xc004892900, 0xc004892900, {0x112c130, 0xc00274f080})
        honnef.co/go/[email protected]/go/ir/builder.go:500 +0x1db
honnef.co/go/tools/go/ir.(*builder).stmt(0xed5700, 0xc004892900, {0x112c640, 0xc0028421a0})
        honnef.co/go/[email protected]/go/ir/builder.go:2142 +0x1ab8
honnef.co/go/tools/go/ir.(*builder).stmtList(0x4, 0xc004327080, {0xc0028421c0, 0x2, 0x20})
        honnef.co/go/[email protected]/go/ir/builder.go:752 +0x67
honnef.co/go/tools/go/ir.(*builder).stmt(0xc004892900, 0xc004892900, {0x112c0d0, 0xc0015782d0})
        honnef.co/go/[email protected]/go/ir/builder.go:2189 +0xd05
honnef.co/go/tools/go/ir.(*builder).buildFunction(0xc0058e7a40, 0xc004892900)
        honnef.co/go/[email protected]/go/ir/builder.go:2301 +0x44a
honnef.co/go/tools/go/ir.(*builder).buildFuncDecl(0xc0048e7ea0, 0xc0048a4000, 0xc001578300)
        honnef.co/go/[email protected]/go/ir/builder.go:2339 +0x195
honnef.co/go/tools/go/ir.(*Package).build(0xc0048a4000)
        honnef.co/go/[email protected]/go/ir/builder.go:2445 +0xc52
sync.(*Once).doSlow(0xc000179080, 0xc001ddf180)
        sync/once.go:68 +0xd2
sync.(*Once).Do(...)
        sync/once.go:59
honnef.co/go/tools/go/ir.(*Package).Build(...)
        honnef.co/go/[email protected]/go/ir/builder.go:2363
honnef.co/go/tools/internal/passes/buildir.run(0xc001634ea0)
        honnef.co/go/[email protected]/internal/passes/buildir/buildir.go:86 +0x308
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc0008d0cf0)
        github.com/golangci/[email protected]/pkg/golinters/goanalysis/runner_action.go:187 +0x9c4
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
        github.com/golangci/[email protected]/pkg/golinters/goanalysis/runner_action.go:105 +0x1d
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc00018c6e0, {0xf25771, 0x7}, 0xc0010f3f60)
        github.com/golangci/[email protected]/pkg/timeutils/stopwatch.go:111 +0x4a
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc0008d0cf0)
        github.com/golangci/[email protected]/pkg/golinters/goanalysis/runner_action.go:104 +0x85
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0x203d3d2062206669)
        github.com/golangci/[email protected]/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0x67
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze
        github.com/golangci/[email protected]/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x1fd 
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: buildir: package "bug" (isInitialPkg: true, needAnalyzeSource: true): in bug.SecretFromBytes: cannot convert Load <[]byte> t0 ([]byte) to *bug.Secret 
INFO [runner] processing took 4.08 with stages: max_same_issues: 1.597s, path_shortener: 397ns, skip_dirs: 356ns, max_from_linter: 281ns, nolint: 263ns, skip_files: 170ns, cgo: 113ns, filename_unadjuster: 110ns, path_prettifier: 106ns, autogenerated_exclude: 103ns, source_code: 102ns, uniq_by_line: 101ns, identifier_marker: 100ns, exclude: 49ns, sort_results: 43ns, severity-rules: 40ns, exclude-rules: 40ns, path_prefixer: 39ns, diff: 38ns, max_per_file_from_linter: 37ns 
INFO [runner] linters took 6.142474954s with stages: goanalysis_metalinter: 6.074989017s 
INFO File cache stats: 0 entries of total size 0B 
INFO Memory: 65 samples, avg is 176.7MB, max is 258.5MB 
INFO Execution took 6.384884692s                  

Code example or link to a public repository

go.mod
module bug

go 1.17

require github.com/stretchr/testify v1.7.0

require (
        github.com/davecgh/go-spew v1.1.0 // indirect
        github.com/pmezard/go-difflib v1.0.0 // indirect
        gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
go.sum
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
bug.go
package bug

type Secret [32]byte

func SecretFromBytes(buf []byte) (*Secret, bool) {
        if len(buf) != len(Secret{}) {
                return nil, false
        }
        return (*Secret)(buf), true
}
bug_test.go
package bug

import (
        "testing"

        "github.com/stretchr/testify/assert"
        "github.com/stretchr/testify/require"
)

func TestSecretFromBytes(t *testing.T) {
        testCases := []struct {
                Bytes   []byte
                Secret  *Secret
                Success bool
        }{
                {
                        Bytes:   nil,
                        Secret:  nil,
                        Success: false,
                },
                {
                        Bytes:   make([]byte, len(Secret{})),
                        Secret:  &Secret{},
                        Success: true,
                },
                {
                        Bytes:   make([]byte, len(Secret{})-1),
                        Secret:  nil,
                        Success: false,
                },
                {
                        Bytes:   make([]byte, len(Secret{})+1),
                        Secret:  nil,
                        Success: false,
                },
        }
        for _, tc := range testCases {
                secret, ok := SecretFromBytes(tc.Bytes)
                if tc.Success {
                        require.True(t, ok)
                } else {
                        require.False(t, ok)
                }
                assert.Equal(t, tc.Secret, secret)
        }
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdependenciesRelates to an upstream dependency

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions