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

Closed
alandonovan opened this issue Oct 8, 2018 · 2 comments
Closed

cmd/vet: bool checker issues a triangular number of errors #28086

alandonovan opened this issue Oct 8, 2018 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@alandonovan
Copy link
Contributor

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
Copy link
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
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 The path to resolution is known, but the work has not been done. 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
@gopherbot
Copy link

Change https://golang.org/cl/176457 mentions this issue: go/analysis/passes/bools: eliminate quadratic runtime, output

@golang golang locked and limited conversation to collaborators May 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants