Commits

Greg Price  committed 0db4ac0

fix segmentation fault on parsing some invalid Python

  • Participants
  • Parent commits eb44d13

Comments (0)

Files changed (2)

File pypy/interpreter/astcompiler/asthelpers.py

         return self.elts
 
     def set_context(self, ctx):
-        for elt in self.elts:
-            elt.set_context(ctx)
-        self.ctx = ctx
+        if self.elts:
+            for elt in self.elts:
+                elt.set_context(ctx)
+            self.ctx = ctx
 
 
 class __extend__(ast.Attribute):

File pypy/interpreter/astcompiler/test/test_compiler.py

 
     st = simple_test
 
+    def error_test(self, source, exc_type):
+        py.test.raises(exc_type, self.simple_test, source, None, None)
+
     def test_long_jump(self):
         func = """def f(x):
     y = 0
         self.simple_test(stmt, "type(x)", int)
 
     def test_tuple_assign(self):
+        yield self.error_test, "() = 1", SyntaxError
         yield self.simple_test, "x,= 1,", "x", 1
         yield self.simple_test, "x,y = 1,2", "x,y", (1, 2)
         yield self.simple_test, "x,y,z = 1,2,3", "x,y,z", (1, 2, 3)
         yield self.simple_test, "x,y,z,t = 1,2,3,4", "x,y,z,t", (1, 2, 3, 4)
         yield self.simple_test, "x,y,x,t = 1,2,3,4", "x,y,t", (3, 2, 4)
+        yield self.simple_test, "[] = []", "1", 1
         yield self.simple_test, "[x]= 1,", "x", 1
         yield self.simple_test, "[x,y] = [1,2]", "x,y", (1, 2)
         yield self.simple_test, "[x,y,z] = 1,2,3", "x,y,z", (1, 2, 3)