Commits

Armin Rigo  committed aba0616

Issue 1247: Fix for the syntax "()[...]".

  • Participants
  • Parent commits 4a2de54

Comments (0)

Files changed (2)

File pypy/interpreter/astcompiler/optimize.py

 
     def as_constant_truth(self, space):
         """Return the truth of this node if known."""
-        raise AssertionError("only for expressions")
-
-    def as_constant(self):
-        """Return the value of this node as a wrapped constant if possible."""
-        raise AssertionError("only for expressions")
-
-    def accept_jump_if(self, gen, condition, target):
-        raise AssertionError("only for expressions")
-
-
-class __extend__(ast.expr):
-
-    def as_constant_truth(self, space):
         const = self.as_constant()
         if const is None:
             return CONST_NOT_CONST
         return int(space.is_true(const))
 
     def as_constant(self):
+        """Return the value of this node as a wrapped constant if possible."""
         return None
 
     def accept_jump_if(self, gen, condition, target):
+        raise AssertionError("only for expressions")
+
+
+class __extend__(ast.expr):
+
+    def accept_jump_if(self, gen, condition, target):
         self.walkabout(gen)
         if condition:
             gen.emit_jump(ops.POP_JUMP_IF_TRUE, target, True)

File pypy/interpreter/test/test_compiler.py

             ('a = 14%4', '(2)'),                    # binary modulo
             ('a = 2+3', '(5)'),                     # binary add
             ('a = 13-4', '(9)'),                    # binary subtract
-            # ('a = (12,13)[1]', '(13)'),             # binary subscr - pointless optimization
+            ('a = (12,13)[1]', '(13)'),             # binary subscr
             ('a = 13 << 2', '(52)'),                # binary lshift
             ('a = 13 >> 2', '(3)'),                 # binary rshift
             ('a = 13 & 7', '(5)'),                  # binary and
         asm = dis_single('a="x"*1000')
         assert '(1000)' in asm
 
+    def test_folding_of_binops_on_constants_crash(self):
+        compile('()[...]', '', 'eval')
+        # assert did not crash
+
     def test_dis_stopcode(self):
         source = """def _f(a):
                 print a