summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2019-03-21 23:33:02 (GMT)
committerGitHub <noreply@github.com>2019-03-21 23:33:02 (GMT)
commit9a0000d15d27361eaa47b77600c7c00a9787a894 (patch)
tree8366b22576a95d72d291e34121ef0c71ff6f9fe8 /Lib
parentaedc273fd90e31c7a20904568de3115f8957395b (diff)
downloadcpython-9a0000d15d27361eaa47b77600c7c00a9787a894.zip
cpython-9a0000d15d27361eaa47b77600c7c00a9787a894.tar.gz
cpython-9a0000d15d27361eaa47b77600c7c00a9787a894.tar.bz2
bpo-36256: Fix bug in parsermodule when parsing if statements (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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_parser.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py
index 5548a87..bfa0a5a 100644
--- a/Lib/test/test_parser.py
+++ b/Lib/test/test_parser.py
@@ -319,6 +319,10 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
self.check_suite("try: pass\nexcept: pass\nelse: pass\n"
"finally: pass\n")
+ def test_if_stmt(self):
+ self.check_suite("if True:\n pass\nelse:\n pass\n")
+ self.check_suite("if True:\n pass\nelif True:\n pass\nelse:\n pass\n")
+
def test_position(self):
# An absolutely minimal test of position information. Better
# tests would be a big project.