Skip to content

Commit 9ed36d5

Browse files
authored
gh-113602: Bail out when the parser tries to override existing errors (#113607)
Signed-off-by: Pablo Galindo <[email protected]>
1 parent 8ff44f8 commit 9ed36d5

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
@@ -2360,6 +2360,8 @@ def test_error_parenthesis(self):
23602360
"""
23612361
self._check_error(code, "parenthesis '\\)' does not match opening parenthesis '\\['")
23622362

2363+
self._check_error("match y:\n case e(e=v,v,", " was never closed")
2364+
23632365
# Examples with dencodings
23642366
s = b'# coding=latin\n(aaaaaaaaaaaaaaaaa\naaaaaaaaaaa\xb5'
23652367
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
@@ -311,6 +311,10 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,
311311
Py_ssize_t end_lineno, Py_ssize_t end_col_offset,
312312
const char *errmsg, va_list va)
313313
{
314+
// Bail out if we already have an error set.
315+
if (p->error_indicator && PyErr_Occurred()) {
316+
return NULL;
317+
}
314318
PyObject *value = NULL;
315319
PyObject *errstr = NULL;
316320
PyObject *error_line = NULL;

0 commit comments

Comments
 (0)