diff --git a/test/bytecode_3.7_run/01_if_and_if_bug.pyc b/test/bytecode_3.7_run/01_if_and_if_bug.pyc new file mode 100644 index 00000000..45c20ede Binary files /dev/null and b/test/bytecode_3.7_run/01_if_and_if_bug.pyc differ diff --git a/test/simple_source/bug36/01_if_and_if_bug.py b/test/simple_source/bug36/01_if_and_if_bug.py new file mode 100644 index 00000000..9a529595 --- /dev/null +++ b/test/simple_source/bug36/01_if_and_if_bug.py @@ -0,0 +1,16 @@ +# Bug in 3.6 was not taking "else" branch after compond "if" +# In earlier versions we had else detection needed here. + +def f(a, b, c): + if a and b: + x = 1 + else: + x = 2 + if c: + x = 3 + return(x) + +assert f(True, True, True) == 3 +assert f(True, True, False) == 1 +assert f(True, False, True) == 3 +assert f(True, False, False) == 2 diff --git a/uncompyle6/parsers/parse37.py b/uncompyle6/parsers/parse37.py index 8e497c6c..0ba2c93b 100644 --- a/uncompyle6/parsers/parse37.py +++ b/uncompyle6/parsers/parse37.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017-2018 Rocky Bernstein +# Copyright (c) 2017-2019 Rocky Bernstein # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -73,11 +73,11 @@ class Python37Parser(Python36Parser): compare_chained37 ::= expr compare_chained1a_37 compare_chained37 ::= expr compare_chained1b_37 compare_chained2a_37 ::= expr COMPARE_OP POP_JUMP_IF_TRUE JUMP_FORWARD - compare_chained2b_37 ::= expr COMPARE_OP POP_JUMP_IF_FALSE JUMP_FORWARD + compare_chained2b_37 ::= expr COMPARE_OP COME_FROM POP_JUMP_IF_FALSE JUMP_FORWARD ELSE compare_chained1a_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE compare_chained2a_37 ELSE POP_TOP COME_FROM compare_chained1b_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE - compare_chained2b_37 ELSE POP_TOP JUMP_FORWARD COME_FROM + compare_chained2b_37 POP_TOP JUMP_FORWARD COME_FROM """ def customize_grammar_rules(self, tokens, customize): diff --git a/uncompyle6/semantics/customize3.py b/uncompyle6/semantics/customize3.py index 5dce03f7..d8fa1200 100644 --- a/uncompyle6/semantics/customize3.py +++ b/uncompyle6/semantics/customize3.py @@ -922,7 +922,7 @@ def customize_for_version3(self, version): (-4, 19)), 'compare_chained1b_37': ( ' %[3]{pattr.replace("-", " ")} %p %p', (0, 19), - (-5, 19)), + (-4, 19)), 'compare_chained2a_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)), 'compare_chained2b_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)),