Skip to content

RangeLiteral records whether the step was written - #6

Merged
revarbat merged 1 commit into
mainfrom
implicit-step
Aug 22, 2026
Merged

RangeLiteral records whether the step was written#6
revarbat merged 1 commit into
mainfrom
implicit-step

Conversation

@revarbat

Copy link
Copy Markdown
Member

[a:b] and [a:1:b] parsed to identical ASTs — makeRangeLiteral synthesizes the 1.0 for the two-argument form, and nothing recorded that it had done so.

That is fine for evaluating the range, but it discards the one thing needed to tell a typo from a choice: [5:0] is almost always [5:-1:0] written wrong, while [5:1:0] is someone saying what they meant. The evaluator wants to warn about the first and stay quiet about the second.

Change

  • RangeLiteral::implicitStep, set by makeRangeLiteral when the step argument is absent. The synthesized node stays exactly where it was, so every consumer that only wants the value is untouched.
  • toString() prints back the form that was written. Previously [5:0] round-tripped to [5 : 1 : 0] — a program that behaves identically but now reads as an explicit step, so reformatting a file would have quietly suppressed the warning for it.
  • JSON carries the flag, so a toJson/fromJson round-trip does not lose it either.

Tests

648 existing tests pass, plus one new round-trip test pinning that [5:0] and [5:1:0] both survive a print/reparse cycle as themselves.

🤖 Generated with Claude Code

`[a:b]` and `[a:1:b]` produced identical ASTs, because makeRangeLiteral
synthesizes the 1.0 for the two-argument form. That is fine for evaluating
the range -- the value is the same either way -- but it throws away the one
thing the evaluator needs to tell a typo from a choice: `[5:0]` is almost
always `[5:-1:0]` written wrong, while `[5:1:0]` is someone saying what they
meant.

So keep a flag. The synthesized step node stays exactly where it was, so
every consumer that just wants the value is untouched.

toString() now prints back the form that was written. Emitting the
synthesized step for a two-argument range produced a program that behaves
identically but reads as an explicit step -- so reformatting a file would
have quietly suppressed the evaluator's warning for it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@revarbat
revarbat merged commit ade1d62 into main Aug 22, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant