Fix RuleContext invariant violations in test code#40
Draft
Fix RuleContext invariant violations in test code#40
Conversation
Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix RuleContext invariant violations with parent and invokingState
Fix RuleContext invariant violations in test code
Feb 12, 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.
RuleContextdocuments that root nodes must haveparent == nullANDinvokingState == -1, but test code was creating contexts withparent == nullandinvokingState >= 0, violating this invariant.Changes
Test fixes:
TreesTest.java: Changed root context creation frominvokingState=0to-1(lines 55, 170)ExpectedTokensTest.java: Fixed call stack simulation to useParserRuleContext.emptyContext()as proper root (lines 163-164, 170)Documentation:
RuleContext.java: Clarified invariant applies to "actual parse tree" roots and removed TODO comments acknowledging the confusionExample
Before:
After:
The
isEmpty()method (which checksinvokingState == -1) andATN.getExpectedTokens()(which walks contexts whileinvokingState >= 0) now work correctly with all test contexts.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.