x/tools/go/analysis/passes/nilness: incorrect "impossible condition: nil != nil"; missing tautological error #70381
Labels
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
Go version
go version go1.23.0 linux/amd64
Output of
go env
in your module/workspace:What did you do?
I believe there is a bug in the nilness checker that incorrectly reports an impossible "nil != nil" and also omits an error in a different location about a tautological comparison. This code demonstrates it:
I checked here: https://github.com/golang/go/issues?page=1&q=is%3Aissue+is%3Aopen+nilness and I can't find anything that matches.
What did you see happen?
Here is a screenshot for clarity:
What did you expect to see?
The above error implies that
a
is alwaysnil
and thereforea != nil
will never happen. That is not true. However, there still is a problem with the code. Because of thereturn
, then theif !hasA
is tautological -- although, that's a different error, and it's not reported, and the error that is reported is not only erroneous but also in the wrong place.This, for example, correctly reports no errors:
So I would expect to see something like this:
Interestingly, if I just get rid of
hasA
and put the expression directly in theif
statement, I get:That's what I would expect to see whether or not I have the boolean value broken out into a different variable.
The text was updated successfully, but these errors were encountered: