]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-36256: Fix bug in parsermodule when parsing if statements (GH-12488) 12493/head
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 21 Mar 2019 23:56:20 +0000 (16:56 -0700)
committerPablo Galindo <Pablogsal@gmail.com>
Thu, 21 Mar 2019 23:56:20 +0000 (23:56 +0000)
commit00eb97b4a7d9a73b88ed7c76faee4e49204d5a00
tree7bdbdf88858bb262060c83eabb766edb1a07c1c3
parentcba5ddf088683859dd022d04cb3726d56f5f0297
bpo-36256: Fix bug in parsermodule when parsing if statements (GH-12488)

bpo-36256: Fix bug in parsermodule when parsing if statements

In the parser module, when validating nodes before starting the parsing with to create a ST in "parser_newstobject" there is a problem that appears when two arcs in the same DFA state has transitions with labels with the same type. For example, the DFA for if_stmt has a state with
two labels with the same type: "elif" and "else" (type NAME). The algorithm tries one by one the arcs until the label that starts the arc transition has a label with the same type of the current child label we are trying to accept. In this case, the arc for "elif" comes before the arc for "else"and passes this test (because the current child label is "else" and has the same type as "elif"). This lead to expecting a namedexpr_test (305) instead of a colon (11). The solution is to compare also the string representation (in case there is one) of the labels to see if the transition that we have is the correct one.
(cherry picked from commit 9a0000d15d27361eaa47b77600c7c00a9787a894)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Lib/test/test_parser.py
Misc/NEWS.d/next/Core and Builtins/2019-03-21-00-24-18.bpo-12477.OZHa0t.rst [new file with mode: 0644]
Modules/parsermodule.c