Repository navigation
Warn about a forvalues range that runs no times, such as 3/1, and suggest the countdown - #407
Conversation
Add EMPTY_FORVALUES_RANGE (warning, severity key emptyForvaluesRange) for a forvalues range whose bounds and step are all numeric literals and which runs zero times. Stata gives no message for these loops. - `a/b` with a > b: `a/b` always counts up by 1, so the message suggests the countdown `a(-1)b`. - `a(s)b` and `a t to b` / `a t : b` whose step points away from b. Ranges with macros or expressions, and a zero step (which Stata rejects with "increment may not be zero"), are not reported. The diagnostic honors sight: ignore / ignore-next. Sight has no code actions, so there is no quick fix. Verified against StataMP 18: 3/1, 1(-1)3, 3(1)1, 3 4 to 1 and 3 4 : 1 run 0 times; 3/3 runs once.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
forvalues j = 3/1 { ... }runs zero times in Stata.a/balways counts up by 1, so witha > bthere is nothing to count, and Stata says nothing. It is almost always a countdown meant as3(-1)1. Sight didn't flag it, so neither users nor a downstream translation tool readingsight check --format jsoncould see the problem.This adds
EMPTY_FORVALUES_RANGE(warning, severity keyemptyForvaluesRange) for aforvaluesrange whose bounds and step are all numeric literals and which runs no times:a/bwitha > b:`forvalues` range `3/1` runs no times (`a/b` counts up); did you mean `3(-1)1`?a(s)bwhose step points away fromb:`forvalues` range `1(-1)3` runs no times (step `-1` counts away from `3`)a t to b(ora t : b) whose implied stept - apoints away fromb:`forvalues` range `3 4 to 1` runs no times (the step from `3` to `4` counts away from `1`)The range covers the range expression after
=. Ranges that run (1/3,3/3,3(-1)1,10 8 to 3), ranges with a macro or expression, and a zero step (which Stata rejects with "increment may not be zero") are not reported.sight: ignoreandsight: ignore-nextsuppress it like the other logic warnings. Sight has no code actions, so there is no quick fix; the message carries the suggested countdown. Documented indocs/diagnostics.mdanddocs/configuration.md.Proof: StataMP 18 runs
3/1,1(-1)3,3(1)1,3 4 to 1and3 4 : 1zero times and3/3once. New unit, provider, andsight check --format jsontests pass, the gates pass (9864 tests, 0 fail), andsight checkover Stata's 3,780 base ados (127 literal ranges) reports none.Reviewed with sol-loop: 1 round with gpt-6.1-sol. Sol verdict: approved
Created with Claude Opus 5.5 in Claude Code (T3 Code); reviewed by gpt-6.1-sol in Codex.
Summary by CodeRabbit
forvaluesranges that run zero times. It supports slash, stepped, andto/colon forms and defaults to warning severity.