-
-
Notifications
You must be signed in to change notification settings - Fork 407
Open
Labels
Description
With this package:
% cat a.go
package x
import "reflect"
func A() {
rv := reflect.ValueOf("a")
var iv any = rv.Interface()
_ = iv
}
% cat b.go
package x
import (
"os"
"syscall"
)
func B() {
_, err := os.Stat("b.go")
_ = err == syscall.ENOENT
}
staticcheck reports no errors:
% staticcheck -checks=ST1023
[no error]
if b.go is changed to:
package x
import "os"
func B() {
_, err := os.Stat("b.go")
_ = err
}
Then it (correctly) reports that any is superfluous here:
% staticcheck -checks=ST1023
a.go:7:9: should omit type any from declaration; it will be inferred from the right-hand side (ST1023)
I'm confused why it doesn't report the error if it imports syscall anywhere in the package? I think this might be a bug?
% staticcheck -debug.version
staticcheck (devel, v0.7.0-0.dev.0.20260225220524-31e1ee5e554a)
Compiled with Go version: go1.26.1
Main module:
honnef.co/go/tools@v0.7.0-0.dev.0.20260225220524-31e1ee5e554a
Dependencies:
github.com/BurntSushi/toml@v1.4.1-0.20240526193622-a339e1f7089c (sum: h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=)
golang.org/x/exp/typeparams@v0.0.0-20231108232855-2478ac86f678 (sum: h1:1P7xPZEwZMoBoz0Yze5Nx2/4pxj6nw9ZqHWXqP0iRgQ=)
golang.org/x/mod@v0.31.0 (sum: h1:HaW9xtz0+kOcWKwli0ZXy79Ix+UW/vOfmWI5QVd2tgI=)
golang.org/x/sync@v0.19.0 (sum: h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=)
golang.org/x/tools@v0.40.1-0.20260108161641-ca281cf95054 (sum: h1:CHVDrNHx9ZoOrNN9kKWYIbT5Rj+WF2rlwPkhbQQ5V4U=)
% go version
go version go1.26.1 linux/amd64
% go env -changed
CC='cc'
CXX='c++'
GOBIN='/home/martin/.local/gobin'
GOCACHE='/tmp/go/cache'
GOFLAGS='-modcacherw'
GOTMPDIR='/tmp/go/tmp'
Reactions are currently unavailable