-
-
Notifications
You must be signed in to change notification settings - Fork 405
Closed
Description
env HOME=${WORK}/.home
exec go version
exec staticcheck --version
exec go build f.go
exec staticcheck f.go
-- f.go --
package p
type T struct {
Foo int
}
// Ensure T is comparable.
var _ = T{} == T{}
> exec go version
[stdout]
go version go1.26-devel_8282b72d62 2025-08-06 14:34:39 -0700 linux/amd64
> exec staticcheck --version
[stdout]
staticcheck (devel, v0.7.0-0.dev.0.20250708155414-ba737e5a0f56)
> exec go build f.go
> exec staticcheck f.go
[stdout]
f.go:8:9: identical expressions on the left and right side of the '==' operator (SA4000)
[exit status 1]
Can we add an exception so that var _ = T{} == T{} does not trigger "identical expressions on the left and right" errors?
There are other ways to assert that a type is comparable at build time, like using a map (var _ map[T]struct{}) or instantiating a generic func with a comparable constraint, but they both seem more convoluted than simply comparing an empty T to itself.
Reactions are currently unavailable