Fix for(;;) NullReferenceException in parser - #113
Merged
Conversation
…in FOR rules - Update 4 FOR grammar rules in CParser.jay to use reference type null checking (`$4 is ExpressionStatement es ? es.Expression : null`) - Make ForStatement.ContinueExpression nullable and skip condition emission when null (infinite loop until break) - Regenerate parser via prebuild.sh - Add tests for for(;;), for(i=0;;i++), for(i=0;i<10;), for(;i<5;i++) Agent-Logs-Url: https://github.com/praeclarum/CLanguage/sessions/4fd85394-830c-4edd-b5a1-71623366c29b Co-authored-by: praeclarum <323548+praeclarum@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix NullReferenceException in parser for infinite for loops
Fix for(;;) NullReferenceException in parser
Mar 31, 2026
praeclarum
marked this pull request as ready for review
March 31, 2026 20:29
praeclarum
requested changes
Mar 31, 2026
praeclarum
left a comment
Owner
There was a problem hiding this comment.
Instead of $4 is ExpressionStatement es4a ? es4a.Expression : null etc I would prefer the simpler ($4 as ExpressionStatement)?.Expression. Unless that doesn't work for some reason...
Use ($4 as ExpressionStatement)?.Expression instead of pattern matching. Agent-Logs-Url: https://github.com/praeclarum/CLanguage/sessions/3f96ebb4-83a6-41af-bf99-d72fe14ad18f Co-authored-by: praeclarum <323548+praeclarum@users.noreply.github.com>
Contributor
Author
Updated all 4 rules to use |
praeclarum
approved these changes
Mar 31, 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.
for(;;)and other for-loops with empty expressions crash withNullReferenceExceptionbecauseexpression_statement: ';'returnsnull, and the FOR grammar rules blindly cast toExpressionStatement.Changes
CParser.jay— All 4 FOR rules useaswith null-conditional operator instead of direct cast:ForStatement.cs—ContinueExpressionmade nullable;DoEmitskips the conditional branch when null (infinite loop untilbreak)CParser.cs— Regenerated viaprebuild.shfor(;;),for(i=0;;i++),for(i=0;i<10;),for(;i<5;i++)