Fix infinite loops in parser and support nested IF#25
Merged
associate-1 merged 1 commit intomainfrom Feb 19, 2026
Merged
Conversation
The parser would enter infinite loops (consuming memory until OOM) when encountering: (1) nested/replicated IF within an IF block, and (2) unknown type declarations inside variant receive CASE blocks. Both caused by parsing loops that failed to advance the token position on unrecognized constructs. Fix nested IF by detecting IF tokens as choices in parseIfStatement and recursively parsing them, storing in a new IfChoice.NestedIf field. Codegen flattens non-replicated nested IFs and emits replicated ones as loops with a _ifmatched flag. Add progress guards to all parser loops (IF, CASE, ALT, variant receive) as a safety net. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dboreham
approved these changes
Feb 19, 2026
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.
Summary
IFwithinIFblocks causedparseExpressionto fail without advancing the cursor, and (2) unknown type declarations in variant? CASEblocks caused the same stall pattern.IF(choices inlined into parent chain) and replicatedIF i = 0 FOR n(emitted as a loop with_ifmatchedflag). This is a common occam idiom for searching arrays.IF,CASE,ALT, variant receive) as a safety net against future infinite loop regressions.Test plan
go test ./...).occfiles terminate without hanging (previously 4 of 9 caused OOM)🤖 Generated with Claude Code