fix break inside of for loops that use next (#1436)#1441
Open
ktegan wants to merge 2 commits intohsutter:mainfrom
Open
fix break inside of for loops that use next (#1436)#1441ktegan wants to merge 2 commits intohsutter:mainfrom
ktegan wants to merge 2 commits intohsutter:mainfrom
Conversation
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.
This provides a simple solution to issue #1436 based on a the following comment
"break" won't [work] until we do extra work to implement that using a flag and implementing "break" as "_for_break = true; continue;.This would need code review because: there may be more elegant ways to do this, there are some details I'm not sure about (can print_cpp2() replace an emit() call?), and more testing for correctness would need to be done.
I think my biggest question is whether we should follow what the comment suggests or use an alternative approach where we define a default label for every loop and when there is a break that does not include a label add the label of the innermost loop to that break statement. If we used this labeled break solution the generated cpp1 code would use CPP2_CONTINUE_BREAK() to produce a goto statement instead of the solution in this PR which adds a variable and may require a comparison (check if
_for_breakis true) on every iteration through the loop.