Warn about backwards ranges only when the step was not written - #108
Merged
Conversation
0.40.0 added the reference's backwards-range warning, and put it in
expandIterable so every iterating construct got it from one place. Both
halves of that turn out to be wrong.
Wrong place: the reference reports this against the range LITERAL, so
`r = [5:0];` warns even though nothing ever iterates r. We reported it at
iteration and missed that case entirely.
Wrong scope: `[5:1:0]` and `[0:-1:5]` warned too. Writing the step out is a
statement of intent -- the warning exists for the author who wrote `[5:0]`
meaning `[5:-1:0]` and got a silent empty loop, not for someone who spelled
out a step and meant it.
Both are fixed by the same move. The check now lives in applyRange, the
single point where a range literal becomes a value in either engine, gated
on the parser's new RangeLiteral::implicitStep. Construction-time is where
the reference has it, and it is the only place the flag exists.
That deletes more than it adds: RangeDirectionFn, rangeDirectionWarning()
and seven per-call-site lambdas all go, since one construction site covers
for, list comprehensions, intersection_for, chr() and children() at once.
An implicit step is always exactly 1, so the reference's second wording
("begin is smaller than the end, but step is negative") can no longer arise
and is gone. A test pins that it stays unreachable.
Verified against the real binary for placement, and end-to-end through the
CLI under both engines.
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.
Follow-up to #107, which added the backwards-range warning in 0.40.0 and got two things wrong.
Wrong place
The reference reports this against the range literal:
We warned at iteration, so we missed that case entirely.
Wrong scope
[5:1:0]and[0:-1:5]warned too. Writing the step out is a statement of intent — the warning is for the author who wrote[5:0]meaning[5:-1:0]and got a silent empty loop, not for someone who spelled out a step and meant it.This is a deliberate divergence from the reference, which warns for the explicit forms as well.
One move fixes both
The check moves to
applyRange— the single point where a range literal becomes a value in either engine — gated on the parser's newRangeLiteral::implicitStep(BelfrySCAD/openscad_cpp_parser#6). Construction-time is where the reference has it, and it is the only place the flag exists.It deletes more than it adds:
RangeDirectionFn,rangeDirectionWarning()and seven per-call-site lambdas all go, because one construction site coversfor, list comprehensions,intersection_for,chr()andchildren()at once.An implicit step is always exactly
1, so the reference's second wording ("begin is smaller than the end, but step is negative") can no longer arise. Removed, with a test pinning that it stays unreachable — if it ever fires again, the gate has been widened back to explicit steps.Verification
OSCAD_BYTECODE_VM=0and=1)OpenSCAD-dev.app— that is how the never-iterated case surfaced🤖 Generated with Claude Code