Open josharian opened 3 years ago
Actually, the rewritten form allows the Go compiler to detect the issue; Staticcheck didn't contribute to that.
This might be worth adding a check for. At the same time, I want to add a check that transforms from the first to the second form, in which case we'd get the compile error for free, but even then we might want to flag differently shaped boolean expressions that are impossible.
flag differently shaped boolean expressions that are impossible.
One note on that, taken from a comment I wrote in the compiler (swt.go):
// Don't check for duplicate bools. Although the spec allows it,
// (1) the compiler hasn't checked it in the past, so compatibility mandates it, and
// (2) it would disallow useful things like
// case GOARCH == "arm" && GOARM == "5":
// case GOARCH == "arm":
// which would both evaluate to false for non-ARM compiles.
So there are some legit cases there.
Yeah, we could only check this symbolically, otherwise build tags will ruin everything.
False negative on this (real) code:
Rewriting it to the equivalent, simpler form makes the bug obvious, and also enables staticcheck to catch it:
Output:
System details: