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: false positive when only use is constant expression #812

Closed
peterbourgon opened this issue Aug 20, 2020 · 2 comments
Closed

unused: false positive when only use is constant expression #812

peterbourgon opened this issue Aug 20, 2020 · 2 comments
Labels
false-positive started Issues we've started working on

Comments

@peterbourgon
Copy link

peterbourgon commented Aug 20, 2020

$ staticcheck -version
staticcheck 2020.1.5

$ staticcheck -debug.version
staticcheck 2020.1.5

Compiled with Go version: go1.14.4
Main module:
        honnef.co/go/tools@v0.0.1-2020.1.5 (sum: h1:nI5egYTGJakVyOryqLs1cQO5dO0ksin5XXs2pspk75k=)
Dependencies:
        github.com/BurntSushi/toml@v0.3.1 (sum: h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=)
        golang.org/x/tools@v0.0.0-20191130070609-6e064ea0cf2d (sum: h1:/iIZNFGxc/a7C3yWjGcnboV+Tkc7mxr+p6fDztwoxuM=)

$ go version
go version go1.15 darwin/amd64

go env provided upon request.

package main

import (
	"io"
	"unsafe"
)

var (
	w  io.Writer
	sz = unsafe.Sizeof(w)
)

func main() {
	println(sz)
}
$ go run main.go
16

$ staticcheck main.go
main.go:9:2: var w is unused (U1000)
@peterbourgon peterbourgon added false-positive needs-triage Newly filed issue that needs triage labels Aug 20, 2020
@dgryski
Copy link

dgryski commented Aug 20, 2020

A workaround: sz = unsafe.Sizeof((io.Writer)(nil))

@dominikh dominikh removed the needs-triage Newly filed issue that needs triage label Aug 20, 2020
@dominikh dominikh changed the title unused: false positive for zero value interface at package level unused: false positive when only use is constant expression May 30, 2021
@dominikh dominikh added the started Issues we've started working on label Jun 4, 2022
@kortschak
Copy link
Contributor

I see a similar case that I can't see a similar work around for.

package main

import "unsafe"

type t struct {
	int
}

const s = unsafe.Sizeof(t{})

func main() {
	println(s)
}
$  staticcheck              
main.go:5:6: type t is unused (U1000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive started Issues we've started working on
Projects
None yet
Development

No branches or pull requests

4 participants