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

structcheck returns false positives for embedded structs #826

Closed
3 tasks done
valyala opened this issue Oct 17, 2019 · 12 comments · Fixed by #3125
Closed
3 tasks done

structcheck returns false positives for embedded structs #826

valyala opened this issue Oct 17, 2019 · 12 comments · Fixed by #3125
Labels
false positive An error is reported when one does not exist
Projects

Comments

@valyala
Copy link

valyala commented Oct 17, 2019

Thank you for creating the issue!

  • 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).

Please include the following information:

Version of golangci-lint
$ golangci-lint --version
golangci-lint has version v1.21.0 built from (unknown, mod sum: "h1:HxAxpR8Z0M8omihvQdsD3PF0qPjlqYqp2vMJzstoKeI=") on (unknown)
Config file
$ cat .golangci.yml
cat: .golangci.yml: No such file or directory
Go environment
$ go version && go env
go version go1.13.1 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/valyala/.cache/go-build"
GOENV="/home/valyala/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/valyala/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/valyala/work/go-src"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/valyala/work/go-src/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/valyala/work/VictoriaMetrics/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 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build974883207=/tmp/go-build -gno-record-gcc-switches"

See false positives here: https://github.com/VictoriaMetrics/VictoriaMetrics/commit/97ce4e03a57825a783a28e25fc88b9a9e9e09c3c/checks?check_suite_id=269491276

@tpounds tpounds added the false positive An error is reported when one does not exist label Oct 17, 2019
@jirfag jirfag added this to Needs triage in Zero Bug via automation Oct 18, 2019
@jirfag jirfag moved this from Needs triage to Low priority in Zero Bug Oct 18, 2019
@kortschak
Copy link
Contributor

We see the same thing in gonum/gonum. Locally, this looks like this:

~/src/gonum.org/v1/gonum/graph/encoding/dot [master*]$ golangci-lint run
decode.go:152:2: `graphAttr` is unused (structcheck)
	graphAttr, nodeAttr, edgeAttr encoding.AttributeSetter
	^

This field is used embedded.

@rillig
Copy link

rillig commented Dec 10, 2019

Self-contained example, extracted from https://github.com/rillig/pkglint:

package main

import "fmt"

type Autofix struct {
	autofixShortTerm // embedded with implicit name
}

type autofixShortTerm struct {
	actions []string
}

func (a *Autofix) PrintActions() {
	for _, action := range a.actions { // obviously used
		fmt.Println(action)
	}
}

func main() {
	fix := Autofix{}
	fix.actions = append(fix.actions, "action") // obviously used as well
	fix.PrintActions()
}

Output:

$ golangci-lint.exe run
demo.go:10:2: `actions` is unused (structcheck)
        actions []string

@bnsblue

This comment was marked as off-topic.

@MissingRoberto

This comment has been minimized.

@stale
Copy link

stale bot commented Mar 30, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added stale No recent correspondence or work activity and removed stale No recent correspondence or work activity labels Mar 30, 2022
@rillig
Copy link

rillig commented Apr 9, 2022

Still reproducible:

$ golangci-lint.exe --version
golangci-lint has version v1.45.2 built from (unknown, mod sum: "h1:9I3PzkvscJkFAQpTQi5Ga0V4qWdJERajX1UZ7QqkW+I=") on (unknown)

$ golangci-lint.exe run ./main.go 
main.go:10:2: `actions` is unused (structcheck)
        actions []string
        ^

@cliff-comvex

This comment was marked as off-topic.

@Antonboom

This comment was marked as off-topic.

@ldez

This comment was marked as off-topic.

@Antonboom

This comment was marked as off-topic.

@byashimov
Copy link

byashimov commented Jun 5, 2023

Hey.
Please reopen. This happens with >=1.53.0
1.52 is not affected.

Run @rillig example:

demo.go:10:2: `actions` is unused (structcheck)
        actions []string
        ^
➜  ✗ golangci-lint --version            
golangci-lint has version 1.53.2 built with go1.20.4 from 59a7aaf7 on 2023-06-03T15:04:31Z

A real example.

@ldez
Copy link
Member

ldez commented Jun 5, 2023

structcheck is deprecated, please stop using it.

https://golangci-lint.run/usage/linters/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false positive An error is reported when one does not exist
Projects
No open projects
Zero Bug
  
Closed
Development

Successfully merging a pull request may close this issue.

10 participants