gh-153437: Make pegen output error detection checks after loop body for '*' rules.#153441
Closed
stestagg wants to merge 1 commit into
Closed
gh-153437: Make pegen output error detection checks after loop body for '*' rules.#153441stestagg wants to merge 1 commit into
stestagg wants to merge 1 commit into
Conversation
Currently, the pegen output produces this for '+' rules:
if (_n == 0 || p->error_indicator) {
PyMem_Free(_children);
p->level--;
return NULL;
}
But for '*' rules, no check is done at all, (skipping the _n == 0 makes sesnse of course)
For '*' it's possible for an error to be raised when parsing children, and currently the parser
sets the error flag/exception but does not return NULL, so parent rules might not detect the
error appropriately, as in this code:
if (
(a = _PyPegen_expect_token(p, FSTRING_START)) // token='FSTRING_START'
&&
(b = _loop0_79_rule(p)) // fstring_middle*
&&
(c = _PyPegen_expect_token(p, FSTRING_END)) // token='FSTRING_END'
)
In this example, _PyPegen_expect_token can raise a SyntaxWarning which trips a debug assert.
This change outputs the same p->error_indicator check for '*' rules as for '+' rules.
Contributor
Author
|
Duplicate of #150067 |
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.
Currently, the pegen output produces this for '+' rules after the children have been parsed:
But for '*' rules, no check is done at all, (skipping the
_n == 0makes sesnse of course)For '*' it's possible for an error to be raised when parsing children, and currently the parser sets the error flag/exception but does not return NULL, so parent rules might not detect the error appropriately, as in this code:
In this example, _PyPegen_expect_token can raise a SyntaxWarning which trips a debug assert.
This change outputs the same p->error_indicator check for '*' rules as for '+' rules.
Note, there are lots of rules affected by this change, but it seems to me that this is a latent bug for each of them, even though it might not be possible to trigger an error for all of them.