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

cmd/vet: detect stupid conditions #7622

Closed
rsc opened this issue Mar 24, 2014 · 5 comments

Comments

Projects
None yet
3 participants
@rsc
Copy link
Contributor

commented Mar 24, 2014

It would be nice if vet detected a few obviously stupid boolean conditions. This can
probably be done purely at a syntactic level, without recourse to any type checking.

x == y || x == y
is a redundant test, assuming neither x nor y contains function calls or channel
operations.

x != y || x != z
is not guaranteed to be wrong but almost always is. If y and z are the same then it's
redundant; if y and z are different then it's always true.
@josharian

This comment has been minimized.

Copy link
Contributor

commented Mar 24, 2014

Comment 1:

Not sure whether this belongs in vet (vs golint), but on the topic of stupid boolean
conditions, x == false should be !x.
@josharian

This comment has been minimized.

Copy link
Contributor

commented May 7, 2014

Comment 2:

Owner changed to @josharian.

Status changed to Started.

@josharian

This comment has been minimized.

Copy link
Contributor

commented Jun 26, 2014

Comment 3:

I've come to the conclusion that flagging cases like x == false is a better fit for go
lint, and filed golang/lint#45 accordingly. CL for rsc's
original check coming soon.
@gopherbot

This comment has been minimized.

Copy link

commented Jun 26, 2014

Comment 4:

CL https://golang.org/cl/98120043 mentions this issue.
@josharian

This comment has been minimized.

Copy link
Contributor

commented Jul 2, 2014

Comment 5:

This issue was closed by revision golang/tools@7da5f19.

Status changed to Fixed.

@rsc rsc added fixed labels Jul 2, 2014

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015

@rsc rsc removed the release-go1.4 label Apr 14, 2015

@golang golang locked and limited conversation to collaborators Jun 25, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.