golangci / golangci-lint

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

Panic when run gosimple (rule S1036) with specific code #1278

Closed programmer04 closed 4 years ago

programmer04 commented 4 years ago

Thank you for creating the issue!

Please include the following information:

Version of golangci-lint ```console $ golangci-lint --version golangci-lint has version 1.29.0 built from 6a68907 on 2020-07-20T14:54:31Z ```
Config file ```console # instead of config file run with arguments (for config file the same behavior) $ golangci-lint run --disable-all -E gosimple -v ```
Go environment ```console $ go version && go env go version go1.14.5 darwin/amd64 GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/Users/jakubwarczarek/Library/Caches/go-build" GOENV="/Users/jakubwarczarek/Library/Application Support/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/jakubwarczarek/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/Cellar/go/1.14.5/libexec" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/Cellar/go/1.14.5/libexec/pkg/tool/darwin_amd64" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="" 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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lh/yzgq0xxj1kbc5cbchsjzps_40000gn/T/go-build975986209=/tmp/go-build -gno-record-gcc-switches -fno-common" ```
Verbose output of running ```console $ golangci-lint cache clean $ golangci-lint run --disable-all -E gosimple -v golangci-lint run --disable-all -E gosimple -v INFO [config_reader] Config search paths: [./ /Users/jakubwarczarek/Documents/mm/repErr /Users/jakubwarczarek/Documents/mm /Users/jakubwarczarek/Documents /Users/jakubwarczarek /Users /] INFO [lintersdb] Active 1 linters: [gosimple] INFO [loader] Go packages loading at mode 575 (types_sizes|compiled_files|deps|name|exports_file|files|imports) took 84.457849ms INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 1.739382ms INFO [linters context/goanalysis] analyzers took 11.2244ms with top 10 stages: buildir: 3.206089ms, S1019: 1.02211ms, S1012: 981.546µs, S1028: 967.554µs, S1005: 962.9µs, S1031: 710.379µs, S1039: 692.299µs, S1023: 531.509µs, inspect: 463.143µs, S1024: 365.904µs WARN [linters context] Panic: S1036: package "main" (isInitialPkg: true, needAnalyzeSource: true): unsupported comparison: []*ast.Field and []*ast.Field: goroutine 141 [running]: runtime/debug.Stack(0x1cf897b, 0x3c, 0xc0009d57c0) /opt/hostedtoolcache/go/1.14.4/x64/src/runtime/debug/stack.go:24 +0x9d github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1(0xc00099dc00) /home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:508 +0x1b5 panic(0x1ab8880, 0xc000556370) /opt/hostedtoolcache/go/1.14.4/x64/src/runtime/panic.go:969 +0x166 honnef.co/go/tools/pattern.match(0xc000556320, 0x1a9b480, 0x274e820, 0x1a9b480, 0x274e820, 0x0, 0x0, 0x2) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:245 +0x16bd honnef.co/go/tools/pattern.match(0xc000556320, 0x1a9b480, 0x274e820, 0x1b2f820, 0xc000370d50, 0xc00030f900, 0xa, 0xc00030f930) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:159 +0x15d honnef.co/go/tools/pattern.match(0xc000556320, 0x1b2f820, 0xc000370c30, 0x1b2f820, 0xc000370d50, 0xc000370d50, 0x196, 0xc00030f9fa) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:138 +0x1215 honnef.co/go/tools/pattern.matchAST(0xc000556320, 0x1e84ac0, 0xc00089f620, 0x1e84ac0, 0xc00089f6e0, 0x1b69f01, 0xc00089f6c0, 0xc00030fa01) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:343 +0x619 honnef.co/go/tools/pattern.match(0xc000556320, 0x1b30520, 0xc00089f620, 0x1b30520, 0xc00089f6e0, 0xc00089f6e0, 0x194, 0xc00030fb01) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:183 +0xc27 honnef.co/go/tools/pattern.matchAST(0xc000556320, 0x1e84b80, 0xc000370c60, 0x1e84b80, 0xc000370d80, 0x1b36401, 0xc000370d20, 0xc00030fc01) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:343 +0x619 honnef.co/go/tools/pattern.match(0xc000556320, 0x1b3bda0, 0xc000370c60, 0x1b3bda0, 0xc000370d80, 0xc000370d80, 0x194, 0xc00030fd01) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:183 +0xc27 honnef.co/go/tools/pattern.matchAST(0xc000556320, 0x1e84f00, 0xc000370c90, 0x1e84f00, 0xc000370db0, 0x1, 0x0, 0xc000680000) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:343 +0x619 honnef.co/go/tools/pattern.match(0xc000556320, 0x1b34520, 0xc000370c90, 0x1b34520, 0xc000370db0, 0xc000370db0, 0x194, 0x10) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:183 +0xc27 honnef.co/go/tools/pattern.matchAST(0xc000556320, 0x1e84a80, 0xc000370cc0, 0x1e84a80, 0xc000370de0, 0x1, 0x0, 0x2) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:343 +0x619 honnef.co/go/tools/pattern.match(0xc000556320, 0x1b364a0, 0xc000370cc0, 0x1b364a0, 0xc000370de0, 0x1eb6700, 0x1a92a00, 0x0) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:183 +0xc27 honnef.co/go/tools/pattern.match(0xc000556320, 0x1b364a0, 0xc000370cc0, 0x1a92a00, 0xc000552140, 0x1, 0x0, 0x8) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:215 +0x4ae honnef.co/go/tools/pattern.Binding.Match(0x1d09f49, 0x9, 0x0, 0x0, 0xc000556320, 0x1a92a00, 0xc000552140, 0x1bb5240, 0xc000552101, 0xa264078) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:358 +0xcb honnef.co/go/tools/pattern.match(0xc000556320, 0x1bb5240, 0xc0000912c0, 0x1a92a00, 0xc000552140, 0xc000552140, 0xc0001c7b40, 0x197) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:167 +0xd06 honnef.co/go/tools/pattern.matchNodeAST(0xc000556320, 0x1e868c0, 0xc00008fd10, 0x1b2dc20, 0xc0001c7b40, 0x1, 0x0, 0x1) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:287 +0x646 honnef.co/go/tools/pattern.match(0xc000556320, 0x1bc2a20, 0xc00008fd10, 0x1b2dc20, 0xc0001c7b40, 0x1b364a0, 0xc000370cc0, 0x1) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:172 +0xc9f honnef.co/go/tools/pattern.matchNodeAST(0xc000556320, 0x1e868c0, 0xc00008fd10, 0x1a8d240, 0xc000552120, 0x1, 0x18, 0x100000000000196) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:258 +0xcf honnef.co/go/tools/pattern.match(0xc000556320, 0x1bc2a20, 0xc00008fd10, 0x1a8d240, 0xc000552120, 0x1eb6700, 0x1b37620, 0x0) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:172 +0xc9f honnef.co/go/tools/pattern.Binding.Match(0x1d09f39, 0x3, 0x1e868c0, 0xc00008fd10, 0xc000556320, 0x1a8d240, 0xc000552120, 0x1bb5240, 0x101, 0xa264078) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:368 +0x1aa honnef.co/go/tools/pattern.match(0xc000556320, 0x1bb5240, 0xc000091300, 0x1a8d240, 0xc000552120, 0x1bc7300, 0xc0001c7b80, 0x199) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:167 +0xd06 honnef.co/go/tools/pattern.match(0xc000556320, 0x1bb5240, 0xc000091300, 0x1b37620, 0xc000370e10, 0xc000370e10, 0xc0001c7ba8, 0x196) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:154 +0x1070 honnef.co/go/tools/pattern.matchNodeAST(0xc000556320, 0x1e86e80, 0xc00020b040, 0x1b35da0, 0xc0001c7b80, 0x1, 0xc00054e1b0, 0xc0008a8890) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:287 +0x646 honnef.co/go/tools/pattern.match(0xc000556320, 0x1bd1900, 0xc00020b040, 0x1b35da0, 0xc0001c7b80, 0xc00033e620, 0x1b3bd20, 0xc0001c79c0) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:172 +0xc9f honnef.co/go/tools/pattern.Or.Match(0xc000370360, 0x3, 0x3, 0xc000556310, 0x1b35da0, 0xc0001c7b80, 0x1b7db00, 0x2aba001, 0xa264098) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:478 +0xc0 honnef.co/go/tools/pattern.match(0xc000556310, 0x1b7db00, 0xc00033f4e0, 0x1b35da0, 0xc0001c7b80, 0x0, 0x0, 0x0) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:167 +0xd06 honnef.co/go/tools/pattern.(*Matcher).Match(...) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/pattern/match.go:110 honnef.co/go/tools/lint/lintdsl.Match(0xc000554300, 0x1e87140, 0xc00033f4e0, 0xc000346e00, 0x3, 0x4, 0x1e84980, 0xc0001c7b80, 0x0, 0x0) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/lint/lintdsl/lintdsl.go:27 +0xcc honnef.co/go/tools/simple.CheckUnnecessaryGuard.func1(0x1e84980, 0xc0001c7b80) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/simple/lint.go:1751 +0x82 golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0xc000a020a0, 0xc000143d58, 0x1, 0x1, 0xc0009d7d68) /home/runner/go/pkg/mod/golang.org/x/tools@v0.0.0-20200710042808-f1c4188a97a1/go/ast/inspector/inspector.go:77 +0x9f honnef.co/go/tools/code.Preorder(...) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/code/code.go:480 honnef.co/go/tools/simple.CheckUnnecessaryGuard(0xc000554300, 0xbbbd0a2, 0x2718200, 0xc000890cd0, 0x2) /home/runner/go/pkg/mod/honnef.co/go/tools@v0.0.1-2020.1.4/simple/lint.go:1760 +0xc5 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc00099dc00) /home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:590 +0xa25 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2() /home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:512 +0x2a github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc00033cff0, 0x1c4516f, 0x5, 0xc000143f70) /home/runner/work/golangci-lint/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x50 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc00099dc00) /home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:511 +0x91 github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc0009a0910, 0xc00099dc00) /home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:1059 +0x61 created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze /home/runner/work/golangci-lint/golangci-lint/pkg/golinters/goanalysis/runner.go:1054 +0x306 INFO [runner] processing took 6.186µs with stages: max_same_issues: 3.342µs, skip_dirs: 380ns, nolint: 360ns, max_from_linter: 250ns, cgo: 177ns, identifier_marker: 162ns, path_prettifier: 162ns, skip_files: 162ns, uniq_by_line: 156ns, filename_unadjuster: 155ns, diff: 152ns, autogenerated_exclude: 148ns, max_per_file_from_linter: 79ns, path_shortener: 77ns, severity-rules: 77ns, exclude: 75ns, sort_results: 75ns, exclude-rules: 67ns, source_code: 66ns, path_prefixer: 64ns INFO [runner] linters took 431.334842ms with stages: gosimple: 431.272725ms INFO File cache stats: 0 entries of total size 0B INFO Memory: 7 samples, avg is 70.9MB, max is 71.1MB INFO Execution took 539.079736ms ```

Code which gives the ability to reproduce above behavior ```go package main func main() { obj := make(map[string]interface{}) obj["schema"] = make(map[string]interface{}) if _, ok := obj["schema"].(map[string]interface{})["items"]; ok { obj["schema"].(map[string]interface{})["version"] = 1 } } ```

This bug was originally spotted by using golangci-lint so I put it here to track the status because it affects this project too 🙂 It is caused by upstream dependency go-tools and I've created issue in respective repo dominikh/go-tools#806

Cheers!

SVilgelm commented 4 years ago

Seems it was fixed, so we need to wait when the honnef.co/go/tools will release a new version, so unfortunately we cannot update to the master branch due an error with unused linter:


go run cmd/golangci-lint/main.go run --allow-parallel-runners --disable-all -Egosimple --no-config test_gosimple/...
# github.com/golangci/golangci-lint/pkg/golinters
pkg/golinters/unused.go:16:7: undefined: unused.NewChecker````
SVilgelm commented 4 years ago

The list of liters from honnef.co/go/tools that will need an additional attention during an upgrade:

programmer04 commented 4 years ago

Hey @SVilgelm, the version honnef.co/go/tools v0.0.1-2020.1.5 is fixed and works as expected for the case reported in this issue. Moreover, this version is already in go.mod so I built golangci-lint from the newest commit and tested. Everything works as expected 🎉 hence after release, this can be closed. Thanks for your help 🙂

programmer04 commented 4 years ago

In newest golangci-lint v1.31.0 this bug doesn't exist, so issue is resolved and can be closed