Skip to content

cmd/vet: check for duplicate input to some binary ops #15586

Description

@josharian

[moved from #15570]

@dominikh's staticcheck found some bugs in the standard library -- see #15570. This issue is to consider whether it's worth adding a vet check along the same lines.

The check would be to look for expressions of the form (x BOP x), where:

  • x is not of type float
  • BOP is one of: & && | || == != - / % ^ &^
  • x is a side-effect free expression (see the boolean conditions check)

These expressions are either redundant or have a constant value (with some very rare exceptions, like division and the smallest negative integer), which indicates that they are probably a mistake, and in any case would be better written in another way.

cc @robpike for opinions

cc @valyala in case you are interested in playing with more vet checks :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions