intermediate

Nothing errors and every number is wrong

A pricing service was ported from a hand-written recursive-descent parser to a new expression parser. All 900 unit tests pass. Invoices go out. Three days later finance reports that discounts are being applied to the wrong base.

The symptom

The rule total = base + qty * unit computes (base + qty) * unit. There is no error, no warning, no crash — the program runs and produces a number, and the number is plausible. Small inputs happen to agree, which is why the tests passed: the fixtures use qty = 1 and unit = 1.

Commit first

Commit to a phase before reading further, and commit to a prediction you can check: if you are right about the phase, what will the AST for a + b * c look like, and what will the token stream look like? One of those two will be wrong and the other will be fine — say which, in advance.