Skip to content

ALL-CONT0002 · statement_without_effect

Count statements that compute a value and then throw it away.

This is a deterministic rule for all languages. Read its implementation.

Report a statement whose whole content is one expression that can only produce a value, such as a bare name, a comparison, a literal, or a collection. Nothing happens when the line runs, so it is either a mistake or a line nobody needs to read. The mistake is the common case, and it is usually an assertion that lost its assert, an assignment that lost its target, or a call that lost its parentheses, all of which look like working code and quietly test nothing.

What counts is the statement’s whole content, which is the one node covering exactly the source the statement covers. Everything else beneath a statement is an operand, and an operand says nothing about whether the line did any work, since the 1 inside exit(1) is a literal in a statement that ends the program. Reading the widest node rather than any node underneath is what keeps the two apart in every language. An operation is then the one kind read further, since == compares and stops while &, |, and >> are how several libraries spell a command that runs.

Continue with evidence and references, or open the examples.