Skip to content

Commit 1c381ec

Browse files
[3.11] gh-113602: Bail out when the parser tries to override existing errors (GH-113607) (#113653)
gh-113602: Bail out when the parser tries to override existing errors (GH-113607) (cherry picked from commit 9ed36d5) Signed-off-by: Pablo Galindo <pablogsal@gmail.com> Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
1 parent 9beb565 commit 1c381ec

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

Lib/test/test_syntax.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,8 @@ def test_error_parenthesis(self):
21432143
"""
21442144
self._check_error(code, "parenthesis '\\)' does not match opening parenthesis '\\['")
21452145

2146+
self._check_error("match y:\n case e(e=v,v,", " was never closed")
2147+
21462148
# Examples with dencodings
21472149
s = b'# coding=latin\n(aaaaaaaaaaaaaaaaa\naaaaaaaaaaa\xb5'
21482150
self._check_error(s, r"'\(' was never closed")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix an error that was causing the parser to try to overwrite existing errors
2+
and crashing in the process. Patch by Pablo Galindo

Parser/pegen_errors.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,
299299
Py_ssize_t end_lineno, Py_ssize_t end_col_offset,
300300
const char *errmsg, va_list va)
301301
{
302+
// Bail out if we already have an error set.
303+
if (p->error_indicator && PyErr_Occurred()) {
304+
return NULL;
305+
}
302306
PyObject *value = NULL;
303307
PyObject *errstr = NULL;
304308
PyObject *error_line = NULL;

0 commit comments

Comments
 (0)