diff --git a/test/bytecode_2.4_run/02_loop_continue_dead_code.pyc b/test/bytecode_2.4_run/02_loop_continue_dead_code.pyc new file mode 100644 index 00000000..94a416f8 Binary files /dev/null and b/test/bytecode_2.4_run/02_loop_continue_dead_code.pyc differ diff --git a/test/bytecode_2.6_run/02_loop_continue_dead_code.pyc b/test/bytecode_2.6_run/02_loop_continue_dead_code.pyc new file mode 100644 index 00000000..d4a2ed1d Binary files /dev/null and b/test/bytecode_2.6_run/02_loop_continue_dead_code.pyc differ diff --git a/test/bytecode_2.7_run/02_loop_continue_dead_code.pyc b/test/bytecode_2.7_run/02_loop_continue_dead_code.pyc new file mode 100644 index 00000000..9e814d8c Binary files /dev/null and b/test/bytecode_2.7_run/02_loop_continue_dead_code.pyc differ diff --git a/test/simple_source/bug24/02_loop_continue_dead_code.py b/test/simple_source/bug24/02_loop_continue_dead_code.py new file mode 100644 index 00000000..cbe5008e --- /dev/null +++ b/test/simple_source/bug24/02_loop_continue_dead_code.py @@ -0,0 +1,18 @@ +"""This program is self-checking!""" +# Python 2.4 - 2.7 bug in transforming "else if" to "elif" in Python 2.4 .. 2.7 +# From Issue #377 + +# RUNNABLE! +def loop_continue_dead_code(slots): + for name in slots: + if name: + pass + else: + continue + # The below is dead code + if x: + y() + else: + z() + +loop_continue_dead_code([None, 1]) diff --git a/uncompyle6/semantics/transform.py b/uncompyle6/semantics/transform.py index 3ac5edfb..30751c16 100644 --- a/uncompyle6/semantics/transform.py +++ b/uncompyle6/semantics/transform.py @@ -293,7 +293,8 @@ class TreeTransform(GenericASTTraversal, object): else_suite_index = 1 len_n = len(n) - if len_n == 1 == len(n[0]) and n[0] == "stmt": + # Sometimes stmt is reduced away and n[0] can be a single reduction like continue -> CONTINUE. + if len_n == 1 and isinstance(n[0], SyntaxTree) and len(n[0]) == 1 and n[0] == "stmt": n = n[0][0] elif len_n == 0: return node