Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for loop with literals violates 'loop always iterates more than once' rule #37

Closed
born-in-brooklyn opened this issue Oct 24, 2017 · 2 comments

Comments

@born-in-brooklyn
Copy link

in the case of a structure like this:

FOR i in 1..4 LOOP
/*magic happens*/
END LOOP;

piggly reports 'loop always iterates more than once' . this hard coded loop was put there by design, since it is for calculating a thing exactly 4 times. There is no conditional here, so I fail to see the lack of coverage.

@kputnam
Copy link
Owner

kputnam commented Oct 24, 2017

Yes, that is annoying. However, it's difficult to work support for this in, because it's still possible your loop body could exit early (using an EXIT statement or an exception). So piggly conservatively assumes any loop is capable of executing 0, 1, or 1+ iterations and records if those happen.

One other approach to handling this (besides trying to analyze the loop body, which is probably a ton of work -- exceptions can happen unpredictably, in division by zero, in calls to other procedures, if a value is unexpectedly NULL, etc, or inferring a loop cannot exit early might require evaluating complex conditional expressions) would be to allow users to add comments to annotate their code with hints to piggly.

I'm not sure how that would work in practice, at least in terms of syntax, and how piggly would know exactly which segment of code the comment applies to. But I can vaguely imagine having something like -- piggly: assume loop iterates zero times. This too would be non-trivial, so I don't imagine adding it myself anytime soon.

@born-in-brooklyn
Copy link
Author

understood. no worries.

@kputnam kputnam closed this as completed Apr 21, 2018
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

No branches or pull requests

2 participants