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: struct comparison #1577

Open
s1na opened this issue Jul 17, 2024 · 0 comments
Open

unused: struct comparison #1577

s1na opened this issue Jul 17, 2024 · 0 comments

Comments

@s1na
Copy link

s1na commented Jul 17, 2024

Hello. I'm using unused via golangci-lint. Here is the version of the packages:

❯ golangci-lint --version
golangci-lint has version 1.59.1 built with go1.22.4 from 1a55854 on 2024-06-08T22:05:49Z

❯ go version
go version go1.22.5 darwin/amd64

I can see that the version of go-tools that golanci-lint is using is honnef.co/go/tools v0.4.7.

go env

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/sina/Library/Caches/go-build'
GOENV='/Users/sina/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/sina/dev/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/sina/dev/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/Cellar/go/1.22.5/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/Cellar/go/1.22.5/libexec/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.22.5'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/sina/dev/go/src/github.com/s1na/test-unused-ci/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/cp/k3x0xm3959qf9l0pcbbdxdt80000gn/T/go-build4190770178=/tmp/go-build -gno-record-gcc-switches -fno-common'

I'm running this command:

golangci-lint run

My config is:

linters:
  disable-all: true
  enable:
    - unused

linters-settings:
  unused:
    field-writes-are-uses: false
    generated-is-used: true

This is the code:

package main

import "fmt"

type A struct {
	foo  bool
	bar  bool
	used string
}

func main() {
	a := A{foo: true, bar: true, used: "hi"}
	b := A{foo: true, bar: true, used: "hi"}
	fmt.Printf("%s %s %v\n", a.used, b.used, a == b)
}

unused thinks foo and bar are unused in this case. Their values are read by the struct comparison.

@s1na s1na added false-positive needs-triage Newly filed issue that needs triage labels Jul 17, 2024
@dominikh dominikh removed the needs-triage Newly filed issue that needs triage label Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants