diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2021-10-07 21:33:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-07 21:33:05 (GMT) |
commit | 0219017df7ec41839fd0d56a3076b5f09c58d313 (patch) | |
tree | be87fb79c30e38016710ad6a519be8697fb02653 /Parser | |
parent | 6811fdaec825bd6ab64e358a4b480108f5634d2d (diff) | |
download | cpython-0219017df7ec41839fd0d56a3076b5f09c58d313.zip cpython-0219017df7ec41839fd0d56a3076b5f09c58d313.tar.gz cpython-0219017df7ec41839fd0d56a3076b5f09c58d313.tar.bz2 |
bpo-45408: Don't override previous tokenizer errors in the second parser pass (GH-28812)
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/pegen.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c index 7e2d37c..a989635 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -1342,13 +1342,16 @@ _PyPegen_run_parser(Parser *p) { void *res = _PyPegen_parse(p); if (res == NULL) { + if (PyErr_Occurred() && !PyErr_ExceptionMatches(PyExc_SyntaxError)) { + return NULL; + } 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)) { _PyPegen_check_tokenizer_errors(p); } return NULL; |