RangeLiteral records whether the step was written - #6
Merged
Conversation
`[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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[a:b]and[a:1:b]parsed to identical ASTs —makeRangeLiteralsynthesizes the1.0for 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 bymakeRangeLiteralwhen 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.toJson/fromJsonround-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