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: bool checker issues a triangular number of errors #28086

Open
alandonovan opened this Issue Oct 8, 2018 · 1 comment

Comments

Projects
None yet
4 participants
@alandonovan
Contributor

alandonovan commented Oct 8, 2018

The vet command's bool checker reports progressively more errors as the redundancy in an expression grows. For 7 copies, it reports 1+2+3+4+5+6 errors, because it reports all the errors in each subtree.

$ cat a.go
package a

const k = 1

var _ = k==1||k==1||k==1||k==1||k==1||k==1||k==1
$ vet a.go 
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
a.go:5: redundant or: k == 1 || k == 1
$ vet a.go 2>&1 | wc -l
21

In realistic cases the redundancy is always n=2 so vet only prints n(n-1)/2 = 1 error and there's no problem in practice. However, vet's test suite exercises deeper expressions that lead to redundant errors that are ignored by vet's current test harness because they all match the correct regexp. The new x/tools/go/analysis test harness is more precise and requires multiple expectations for multiple errors. I do not wish to change the checker logic during the migration to the new API, so the task of this issue is to fix the checker logic and remove the workaround from the tests.

@robpike

This comment has been minimized.

Contributor

robpike commented Oct 9, 2018

It might be easier to have vet just stop reporting errors on a given line after some small count is reached. Also more general. This sort of issue with error reporting is an evergreen.

@alandonovan alandonovan self-assigned this Oct 9, 2018

gopherbot pushed a commit to golang/tools that referenced this issue Oct 10, 2018

go/analysis/passes/bools: split out of vet
And rename from "bool" to "bools".

Using analysistest unearthed a minor bug,
github.com/golang/go/issues/28086.
To avoid complicating the diff we work
around it in the tests for now.

Change-Id: I682f33506de778dfdfe97841cd2b16e3d47062b8
Reviewed-on: https://go-review.googlesource.com/c/140737
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>

@bcmills bcmills added the NeedsFix label Oct 23, 2018

@bcmills bcmills added this to the Go1.12 milestone Oct 23, 2018

@ianlancetaylor ianlancetaylor modified the milestones: Go1.12, Go1.13 Dec 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment