-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-36256: Fix bug in parsermodule when parsing if statements #12477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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 triying 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.
Note that the generation of error message at https://github.com/python/cpython/pull/12477/files#diff-73f51bbc1366ee12a4f041d90bbb902dR700 wouldn't handle mismatching NAMEs correctly. Please see https://github.com/python/cpython/pull/10995/files#diff-73f51bbc1366ee12a4f041d90bbb902dR698 for the remaining part of the fix |
An illustration of what I mean:
I.e., it complains on a NAME saying that it expected NAME instead: not very informative! |
Very good, thanks! |
Co-Authored-By: pablogsal <Pablogsal@gmail.com>
Co-Authored-By: pablogsal <Pablogsal@gmail.com>
Co-Authored-By: pablogsal <Pablogsal@gmail.com>
Co-Authored-By: pablogsal <Pablogsal@gmail.com>
Thank you, everyone, for your review and code suggestions! |
Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
GH-12488 is a backport of this pull request to the 3.7 branch. |
…GH-12477) 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 9a0000d) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
This one was tricky! :)
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
triying 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.
https://bugs.python.org/issue36256