Grid bounds tested by hand
0 <= x and x < h and 0 <= y and y < w: (r, c).adj4 or .step(d)
let (h, w): (1..=1000, 1..=1000) = read()
let g: [h, w]Char = read()
let (x, y): (0..h, 0..w) = read()
for (dx, dy) in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
let (nx, ny) = (x + dx, y + dy)
if nx >= 0 and nx < h and ny >= 0 and ny < w:
if g[nx, ny] == '.':
print(nx, ny)let (h, w): (1..=1000, 1..=1000) = read()
domain Row = 0..h
domain Col = 0..w
let g: [Row, Col]Char = read()
let (x, y): (Row, Col) = read()
for (nx, ny) in (x, y).adj4:
if g[nx, ny] == '.':
print(nx, ny)Why
C++ BFS steps with dx/dy arrays and tests 0 <= nx && nx < h && 0 <= ny && ny < w before each read. Get one bound wrong and the program reads outside the grid. In CP Lang a grid over two domains ([Row, Col]T, domain Row = 0..h) knows its own edges: for (nx, ny) in (x, y).adj4 from std.grid yields just the up to four neighbours inside it (adj8 with diagonals), and (x, y).step(d) is None off the grid. There are no bounds to write, and the indices are proven.
The lint fires on an and of comparisons that tests two names against 0 below and a bound above. It has no fix, since the grid's declaration and the loop change together.
The practice it serves
A hand-written pattern the language or the standard library already says in one step. Family: S.containers: deques, lists, grids, randomness.
Not flagged
A near miss: close to the pattern, but not it.
let n: 1..=200000 = read()
let (lo, hi, x, y): (Int, Int, Int, Int) = read()
print(yes(x >= 0 and x < n and lo <= y))Turn it off
For one block, wrap it in with lint(grid_bounds_check: allow):. For a project, add grid_bounds_check = "allow" under [lints] in cp.toml.
Generated from spec/lints/grid_bounds_check, the same record the linter is built from.