fix: raise ParseError instead of AssertionError on unmatched '}' - #604
Merged
Merged
Conversation
An unmatched '}' (e.g. parser.parse('}')) reached an internal assertion
(c_parser.py:127: assert len(self._scope_stack) > 1) rather than returning
through the usual ParseError path. Callers that catch ParseError to handle
parse failures would not catch the AssertionError.
Replace the bare assert with an explicit ParseError so malformed input
travels the documented error path. Fixes eliben#603.
Co-Authored-By: claude-flow <ruv@ruv.net>
eliben
approved these changes
Jul 6, 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.
Problem
parser.parse("}")— an unmatched}— raisesAssertionErrorfrom parser internals instead of the documentedParseError:Callers that catch
ParseErrorto handle parse failures cannot catch theAssertionError.Cause
_pop_scope(c_parser.py:127) uses a bareassertto guard against an empty scope stack. Assertions are for invariant checks, not for user-input validation — and they vanish underpython -O.Fix
Replace the bare assert with an explicit
ParseError:Test
Added
TestUnmatchedRbrace::test_unmatched_rbrace_raises_parse_error— fails on unpatched (AssertionError), passes with the fix. Full suite: 135 passed, 0 regressions (the 1 pre-existingtest_examplesfailure is unrelated —AttributeError: Coordon master HEAD).Fixes #603.
Assisted-by: Claude (Anthropic).