Skip to content

bpo-45408: Don't override previous tokenizer errors in the second parser pass #28812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2021

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Oct 7, 2021

Token *last_token = p->tokens[p->fill - 1];
reset_parser_state(p);
_PyPegen_parse(p);
if (PyErr_Occurred()) {
// Prioritize tokenizer errors to custom syntax errors raised
// on the second phase only if the errors come from the parser.
if (p->tok->done != E_ERROR && PyErr_ExceptionMatches(PyExc_SyntaxError)) {
if (p->tok->done == E_DONE && PyErr_ExceptionMatches(PyExc_SyntaxError)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically where the error was: we were overriding existing tokenizer errors that are different from E_ERROR. In this case we had E_LINECONT.

Copy link
Member

@ammaraskar ammaraskar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix Pablo!

@pablogsal pablogsal merged commit 0219017 into python:main Oct 7, 2021
@pablogsal pablogsal deleted the bpo-45408 branch October 7, 2021 21:33
@miss-islington
Copy link
Contributor

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @pablogsal, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 0219017df7ec41839fd0d56a3076b5f09c58d313 3.10

pablogsal added a commit to pablogsal/cpython that referenced this pull request Oct 7, 2021
…ond parser pass (pythonGH-28812).

(cherry picked from commit 0219017)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
@bedevere-bot
Copy link

GH-28813 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Oct 7, 2021
pablogsal added a commit that referenced this pull request Oct 7, 2021
…ond parser pass (GH-28812). (GH-28813)

(cherry picked from commit 0219017)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants