Issue #644: Low priority: warn on a list literal of one range, [0..181] (NK1281, ADR-362 D5)

Open and answer this issue on GitHub.

enhancement, note · opened 2026-10-17 · updated 2026-10-17 · 0 comments

Low priority — decided, not to be built now (owner, 2026-10-17). Labelled note until the owner moves it to ready.

How it came up

The owner wrote let safety_buffer = [0..181] meaning the numbers 0 to 181. It is a list of one element, the range: printing an element is NK1201 (#638), safety_buffer[110] aborts at run time. Rust has the same trap (vec[0..n]), and Clippy warns on it (single_range_in_vec_init).

Decision

A list literal whose only element is a range is the warning NK1281: a list of one range; the help writes (0..181).collect() for the numbers and [0; 182] for that many equal values (#643). A written type (let r: Vec[Range[i64]] = [0..181]) says the list is meant and silences it. Several ranges ([0..5, 10..15]) are not warned. Rejected: an error (a list of one range is rare, not wrong); nothing.

To build (when it is ready)

  1. Checker: a list literal of exactly one element whose type is a range (a..b, a..<b, a..), with no type written for the binding, argument or field it goes to → NK1281 warning at the literal, help as above (the [0; n] count is the range’s length, inclusive or exclusive).
  2. Tests: [0..181] warns with both helps; [0..<181] names [0; 181]; let r: Vec[Range[i64]] = [0..181] and [0..5, 10..15] do not warn; the program still builds.
  3. Better after #643, so the [v; n] help names something that builds.

Back to Open Issues