Closed jkeys089 closed 2 months ago
Staticcheck strives to only flag definitive bugs. In your examples, it is possible for the values to be untyped nil, and we cannot guess whether the user intended to differentiate between typed and untyped nils or not, and typed nils are not categorically wrong. Even in your examples, SayHi
can be called successfully on the returned typed nils, as the methods don't attempt to dereference the pointers.
As such, I'm afraid this isn't a good fit for us.
I recently ran into a few bugs in some of our projects around interface comparison (i.e. directly checking if an interface var ==
nil
or two different interface vars are == to each other where one isnil
and the other is a concretenil
pointer). I was surprised our CI linter didn't catch these so I wrote a little linter to help prevent these types of issues in the future.The golangci-lint team rejected the PR because they believed this behavior was already caught by
staticcheck
SA4023. However, after some further research (and refining the examples to be a bit closer to real world instances of this bug) I found thatstaticcheck
isn't always detecting this type of bug.Here is a simplified example that I believe should be considered a bug but isn't currently being reported by
staticcheck
:And here is an example of comparing two interface vars:
Would you be interested in a PR that reports these types of issues?