summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-07-27 22:46:59 (GMT)
committerGitHub <noreply@github.com>2020-07-27 22:46:59 (GMT)
commit1332226b32da44087a55e1d71990ee6899dfd28a (patch)
tree453cad89942fcd54a4ef497a56cd55a7e1b66f8b /Parser
parent13efaec2e03288d7ff0ee643589c32bde6c6973c (diff)
downloadcpython-1332226b32da44087a55e1d71990ee6899dfd28a.zip
cpython-1332226b32da44087a55e1d71990ee6899dfd28a.tar.gz
cpython-1332226b32da44087a55e1d71990ee6899dfd28a.tar.bz2
Validate the AST produced by the parser in debug mode (GH-21643)
This will improve the debug experience if something fails in the produced AST. Previously, errors in the produced AST can be felt much later like in the garbage collector or the compiler, making debugging them much more difficult.
Diffstat (limited to 'Parser')
-rw-r--r--Parser/pegen.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c
index e2cbf8b..f615907 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -4,6 +4,7 @@
#include "pegen.h"
#include "string_parser.h"
+#include "ast.h"
PyObject *
_PyPegen_new_type_comment(Parser *p, char *s)
@@ -1137,6 +1138,14 @@ _PyPegen_run_parser(Parser *p)
return RAISE_SYNTAX_ERROR("multiple statements found while compiling a single statement");
}
+#if defined(Py_DEBUG) && defined(Py_BUILD_CORE)
+ if (p->start_rule == Py_single_input ||
+ p->start_rule == Py_file_input ||
+ p->start_rule == Py_eval_input)
+ {
+ assert(PyAST_Validate(res));
+ }
+#endif
return res;
}