Skip to content

Commit 71f4e6a

Browse files
committed
gh-113602: Bail out when the parser tries to override existing errors
Signed-off-by: Pablo Galindo <[email protected]>
1 parent 471aa75 commit 71f4e6a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-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")

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)