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

unused: interface conversion: types.Object is nil, not *types.Func #3938

Closed
4 tasks done
SOF3 opened this issue Jul 3, 2023 · 5 comments · Fixed by #4022
Closed
4 tasks done

unused: interface conversion: types.Object is nil, not *types.Func #3938

SOF3 opened this issue Jul 3, 2023 · 5 comments · Fixed by #4022
Labels
bug Something isn't working dependencies Relates to an upstream dependency feedback required Requires additional feedback

Comments

@SOF3
Copy link

SOF3 commented Jul 3, 2023

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 (e.g., gocritic, go vet, etc.). (https://golangci-lint.run/usage/linters/)

Description of the problem

golangci-lint run starts having the panic error shown below after this commit: SOF3/kelemetry@ca058d3 (the issue is reproduced with and without explicitly setting run.go to 1.20)

Version of golangci-lint

$ golangci-lint version
$ golangci-lint version
golangci-lint has version 1.53.3 built with go1.20.5 from 2dcd82f3 on 2023-06-15T10:50:11Z

Configuration file

$ cat .golangci.yml
linters:
  enable:
    - asasalint
    - asciicheck
    - bidichk
    - bodyclose
    - containedctx
    - contextcheck
    - decorder
    - dogsled
    - dupl
    - dupword
    - durationcheck
    - errchkjson
    - errname
    - errorlint
    - execinquery
    - exhaustive
    - exportloopref
    - forbidigo
    - gci
    - gocheckcompilerdirectives
    - goconst
    - gofumpt
    - goheader
    # - gomnd # TODO
    - goprintffuncname
    - gosec
    - grouper
    - importas
    - interfacebloat
    - lll
    - maintidx
    - makezero
    - misspell
    - nakedret
    - nilerr
    - nosprintfhostport
    - prealloc
    - predeclared
    - reassign
    - revive
    - tenv
    - testpackage
    - thelper
    - tparallel
    - unconvert
    - unparam
    - usestdlibvars
    - whitespace
    # - wrapcheck # TODO

issues:
  exclude-rules:
    - path: pkg/util/errors
      linters: [errorlint]
    - path: cmd/kelemetry/pprof.go
      linters: [gosec]
linters-settings:
  gci:
    sections:
      - standard
      - default
      - prefix(github.com/kubewharf/kelemetry)
  goheader:
    template: |-
      Copyright {{ YEAR }} The Kelemetry Authors.

      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
  gomnd:
    ignored-numbers: ["2", "200", "300", "400", "500"]
    ignored-files:
      - 'pkg/jaeger/tf/config/default/default\.go'
    ignored-functions:
      - 'ctx.AbortWithError'
      - '.*Var'
      - 'os.OpenFile'
  gosec:
    excludes:
      - G404 # not all code are security-sensitive
  importas:
    no-unaliased: true
    alias:
      - pkg: k8s.io/apimachinery/pkg/api/errors
        alias: k8serrors
      - pkg: k8s.io/apimachinery/pkg/apis/meta/v1
        alias: metav1
      - pkg: k8s.io/api/(?P<group>[\w\d]+)/(?P<v1>v\d+)((?P<v2>\w)\w+(?P<v3>\d+))?
        alias: ${group}${v1}${v2}${v3}
      - pkg: k8s.io/apiserver/pkg/apis/audit/v1
        alias: auditv1
      - pkg: k8s.io/client-go/kubernetes/typed/(?P<group>[\w\d]+)/(?P<v1>v\d+)((?P<v2>\w)\w+(?P<v3>\d+))?
        alias: ${group}${v1}${v2}${v3}client
      - pkg: k8s.io/client-go/informers/(?P<group>[\w\d]+)/(?P<v1>v\d+)((?P<v2>\w)\w+(?P<v3>\d+))?
        alias: ${group}${v1}${v2}${v3}informers
      - pkg: k8s.io/client-go/listers/(?P<group>[\w\d]+)/(?P<v1>v\d+)((?P<v2>\w)\w+(?P<v3>\d+))?
        alias: ${group}${v1}${v2}${v3}listers
  lll:
    line-length: 140
    tab-width: 4
  nakedret:
    max-func-lines: 1
  revive:
    rules:
      - name: var-naming
        disabled: true

Go environment

$ go version
go version go1.20.3 linux/amd64

go env not relevant, reproduced on actions/setup-go default setup.

Verbose output of running

$ golangci-lint cache clean 
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /data00/home/chankyin/go/src/github.com/kubewharf/kelemetry /data00/home/chankyin/go/src/github.com/kubewharf /data00/home/chankyin/go/src/github.com /data00/home/chankyin/go/src /data00/home/chankyin/go /data00/home/chankyin /data00/home /data00 / /home/chankyin]
INFO [config_reader] Used config file .golangci.yaml
INFO [lintersdb] Active 54 linters: [asasalint asciicheck bidichk bodyclose containedctx contextcheck decorder dogsled dupl dupword durationcheck errcheck errchkjson errname errorlint execinquery exhaustive exportloopref forbidigo gci gocheckcompilerdirectives goconst gofumpt goheader goprintffuncname gosec gosimple govet grouper importas ineffassign interfacebloat lll maintidx makezero misspell nakedret nilerr nosprintfhostport prealloc predeclared reassign revive staticcheck tenv testpackage thelper tparallel typecheck unconvert unparam unused usestdlibvars whitespace]
INFO [loader] Go packages loading at mode 575 (deps|exports_file|compiled_files|files|imports|name|types_sizes) took 2.975318319s
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 10.480317ms
INFO Memory: 433 samples, avg is 1324.4MB, max is 2280.2MB
INFO Execution took 1m0.581650156s
INFO [linters_context/goanalysis] analyzers took 19m45.479093517s with top 10 stages: buildir: 9m8.645799097s, buildssa: 7m31.085549468s, nilness: 15.756193982s, exhaustive: 12.247307631s, dupl: 10.032241294s, inspect: 9.967798701s, fact_deprecated: 8.347153774s, printf: 7.572203904s, unconvert: 7.544369526s, ctrlflow: 7.496679417s
ERRO [runner] Panic: unused: package "globalinformer" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: types.Object is nil, not *types.Func: goroutine 42553 [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:109 +0x285
panic({0x10069a0, 0xc0bcced320})
        runtime/panic.go:884 +0x213
golang.org/x/exp/typeparams.OriginMethod(0xc05b31a120)
        golang.org/x/exp/typeparams@v0.0.0-20230224173230-c95f2b4c22f2/common.go:112 +0x129
honnef.co/go/tools/unused.(*graph).decl(0xc0384b5608, {0x139b580?, 0xc06584cf00}, {0x0?, 0x0?})
        honnef.co/go/tools@v0.4.3/unused/unused.go:1155 +0x191
honnef.co/go/tools/unused.(*graph).entry(0xc0384b5608)
        honnef.co/go/tools@v0.4.3/unused/unused.go:523 +0xc28
honnef.co/go/tools/unused.run(0xc0b3fcc340)
        honnef.co/go/tools@v0.4.3/unused/unused.go:219 +0x245
github.com/golangci/golangci-lint/pkg/golinters.runUnused(0xc0b3fcc340)
        github.com/golangci/golangci-lint/pkg/golinters/unused.go:61 +0x48
github.com/golangci/golangci-lint/pkg/golinters.NewUnused.func1(0xfe65e0?)
        github.com/golangci/golangci-lint/pkg/golinters/unused.go:31 +0x2f
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc0032fd7e0)
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:195 +0xa25
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
        github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:113 +0x1d
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc00143b680, {0x11376cd, 0x6}, 0xc03a60af48)
        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:112 +0x85
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc0032fd7e0)
        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 +0x208
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: unused: package "globalinformer" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: types.Object is nil, not *types.Func
INFO [runner] processing took 12.192µs with stages: max_same_issues: 3.763µs, skip_dirs: 1.776µs, filename_unadjuster: 1.329µs, nolint: 1.009µs, autogenerated_exclude: 723ns, identifier_marker: 647ns, max_from_linter: 441ns, skip_files: 317ns, fixer: 291ns, exclude-rules: 249ns, diff: 235ns, uniq_by_line: 219ns, cgo: 181ns, sort_results: 157ns, max_per_file_from_linter: 155ns, exclude: 154ns, path_prettifier: 152ns, source_code: 144ns, path_shortener: 91ns, severity-rules: 83ns, path_prefixer: 76ns
INFO [runner] linters took 1m34.501815533s with stages: goanalysis_metalinter: 1m34.501271808s
ERRO Running error: 1 error occurred:
        * can't run linter goanalysis_metalinter: goanalysis_metalinter: unused: package "globalinformer" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: types.Object is nil, not *types.Func

ERRO Timeout exceeded: try increasing it by passing --timeout option

Code example or link to a public repository

SOF3/kelemetry@ca058d3

@SOF3 SOF3 added the bug Something isn't working label Jul 3, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Jul 3, 2023

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez ldez added the dependencies Relates to an upstream dependency label Jul 3, 2023
@ldez ldez changed the title goanalysis_metalinter: interface conversion: types.Object is nil, not *types.Func unused: interface conversion: types.Object is nil, not *types.Func Jul 3, 2023
@ldez
Copy link
Member

ldez commented Jul 3, 2023

Hello,

unused is a part of staticcheck.

$ staticcheck ./...                                   
panic: interface conversion: types.Object is nil, not *types.Func

goroutine 4663 [running]:
golang.org/x/exp/typeparams.OriginMethod(0xc005de10e0)
        /home/ldez/sources/go/pkg/mod/golang.org/x/exp/typeparams@v0.0.0-20221208152030-732eee02a75a/common.go:112 +0x129
honnef.co/go/tools/unused.(*graph).decl(0xc003f3dcd0, {0xa0da18?, 0xc005dc8b40}, {0x0?, 0x0?})
        /home/ldez/sources/go/pkg/mod/honnef.co/go/tools@v0.4.3/unused/unused.go:1155 +0x191
honnef.co/go/tools/unused.(*graph).entry(0xc003f3dcd0)
        /home/ldez/sources/go/pkg/mod/honnef.co/go/tools@v0.4.3/unused/unused.go:523 +0xc28
honnef.co/go/tools/unused.run(0xc0021b4f00)
        /home/ldez/sources/go/pkg/mod/honnef.co/go/tools@v0.4.3/unused/unused.go:219 +0x245
honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0xc008a73da0, {0xa0edf8?, 0xc008a70460})
        /home/ldez/sources/go/pkg/mod/honnef.co/go/tools@v0.4.3/lintcmd/runner/runner.go:992 +0x76a
honnef.co/go/tools/lintcmd/runner.genericHandle({0xa0edf8?, 0xc008a70460}, {0xa0edf8?, 0xc0020eb180?}, 0x0?, 0xc0003ad370, 0xc0088abdb0)
        /home/ldez/sources/go/pkg/mod/honnef.co/go/tools@v0.4.3/lintcmd/runner/runner.go:817 +0x130
created by honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers
        /home/ldez/sources/go/pkg/mod/honnef.co/go/tools@v0.4.3/lintcmd/runner/runner.go:1061 +0x70a
$ staticcheck --version
staticcheck 2023.1.3 (v0.4.3)

Same result with the branch master of staticcheck.

$ staticcheck --version
staticcheck (no version)
$ staticcheck ./...    
panic: interface conversion: types.Object is nil, not *types.Func

goroutine 5071 [running]:
golang.org/x/exp/typeparams.OriginMethod(0xc0070dcf60)
        /home/ldez/sources/go/pkg/mod/golang.org/x/exp/typeparams@v0.0.0-20221208152030-732eee02a75a/common.go:112 +0x129
honnef.co/go/tools/unused.(*graph).decl(0xc01459bcd0, {0xa05c38?, 0xc0018a8300}, {0x0?, 0x0?})
        /home/ldez/sources/golangci-lint/go-tools/unused/unused.go:1155 +0x191
honnef.co/go/tools/unused.(*graph).entry(0xc01459bcd0)
        /home/ldez/sources/golangci-lint/go-tools/unused/unused.go:523 +0xc28
honnef.co/go/tools/unused.run(0xc012b4d5f0)
        /home/ldez/sources/golangci-lint/go-tools/unused/unused.go:219 +0x245
honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0xc0099cc4b0, {0xa07078?, 0xc0099bf860})
        /home/ldez/sources/golangci-lint/go-tools/lintcmd/runner/runner.go:992 +0x76a
honnef.co/go/tools/lintcmd/runner.genericHandle({0xa07078?, 0xc0099bf860}, {0xa07078?, 0xc004891cc0?}, 0x0?, 0xc000432670, 0xc016273d20)
        /home/ldez/sources/golangci-lint/go-tools/lintcmd/runner/runner.go:817 +0x130
created by honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers
        /home/ldez/sources/golangci-lint/go-tools/lintcmd/runner/runner.go:1061 +0x70a

ping @dominikh

@dominikh
Copy link

dominikh commented Jul 3, 2023

Fixed by dominikh/go-tools@65cc494.

@ldez
Copy link
Member

ldez commented Aug 17, 2023

@dominikh The commit is not inside the release branch, is it expected?

dominikh/go-tools@v0.4.3...v0.4.4

$ staticcheck -version 
staticcheck 2023.1.4 (v0.4.4)

$ staticcheck ./...  
panic: interface conversion: types.Object is nil, not *types.Func

goroutine 4762 [running]:
golang.org/x/exp/typeparams.OriginMethod(0xc0031b4900)
        golang.org/x/exp/typeparams@v0.0.0-20221208152030-732eee02a75a/common.go:112 +0x111
honnef.co/go/tools/unused.(*graph).decl(0xc00859fcd0, {0xa028a8?, 0xc002e63ce0}, {0x0?, 0x0?})
        honnef.co/go/tools/unused/unused.go:1155 +0x185
honnef.co/go/tools/unused.(*graph).entry(0xc00859fcd0)
        honnef.co/go/tools/unused/unused.go:523 +0xc14
honnef.co/go/tools/unused.run(0xc008c7c0d0)
        honnef.co/go/tools/unused/unused.go:219 +0x225
honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0xc009161530, {0xa03d88?, 0xc0091179a0})
        honnef.co/go/tools/lintcmd/runner/runner.go:992 +0x6fd
honnef.co/go/tools/lintcmd/runner.genericHandle({0xa03d88?, 0xc0091179a0}, {0xa03d88?, 0xc009116f00?}, 0x0?, 0xc0003cacf0, 0xc0091ea1d0)
        honnef.co/go/tools/lintcmd/runner/runner.go:817 +0x129
created by honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers in goroutine 4761
        honnef.co/go/tools/lintcmd/runner/runner.go:1061 +0x6b5

@ldez ldez added the feedback required Requires additional feedback label Aug 17, 2023
@dominikh
Copy link

Fixed in 2023.1.5 🤦‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Relates to an upstream dependency feedback required Requires additional feedback
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants