Trying the Go vet and Good catch of suspicious OR

Quoting from here, "Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string. Vet uses heuristics that do not guarantee all reports are genuine problems, but it can find errors not caught by the compilers."

Today vet helps me to catch a stupid bug reporting that there is a "suspicious or" in the code, it is a nice catch, can you catch which lines below causing the warning?

if a == 1 && a == 2 {
    a++
}

if a != 1 && a != 2 {
    a++
}

if a == 1 || a == 2 {
    a++
}

if a != 1 || a != 2 {
    a++
}

Good catch! If we want to have code review at scale, source code checking tool is a MUST, even though it is not a magic bullet!

Nevertheless, when you read the quote from Go vet, it can find suspicious constructs like "Printf calls whose arguments do not align with the format string", it sounds like Type checking typically found in the compiler. But it also says that "Vet uses heuristics that do not guarantee all reports are genuine problems, but it can find errors not caught by the compilers.". The term "heuristics" really catches my attention of what approach does Go vet is using for catching bugs?

Comments