← All lints

position_arithmetic

L0101Correctnesswarn

Position arithmetic via .ord

V(v.ord + 1) builds a position from a number

Flagged
domain V = 1..=3
for v in V:
    let _ = V(v.ord + 1)
Write instead
domain V = 1..=3
for v in V:
    if let nxt = v.next:
        print(nxt)

Why

Converting a domain index to .ord, adding or subtracting an offset, and wrapping it back in V(...) bypasses checked neighbor operations. Use v.next, v.prev, or v + k (which return ?V).

The practice it serves

Code that is wrong or almost certainly a bug. Denied by cpl lint. Family: D. Domains, positions and cuts.

Not flagged

A near miss: close to the pattern, but not it.

Near miss
domain V = 1..=3
for v in V:
    print(Int(v) + 1)

Turn it off

For one block, wrap it in with lint(position_arithmetic: allow):. For a project, add position_arithmetic = "allow" under [lints] in cp.toml.

Generated from spec/lints/position_arithmetic, the same record the linter is built from.