Author: Amaury Forgeot d'Arc <[email protected]>
Branch: 
Changeset: r60327:0a0a78963ee3
Date: 2013-01-21 23:12 +0100
http://bitbucket.org/pypy/pypy/changeset/0a0a78963ee3/

Log:    Fix a compiler crash when an ast tree contains the empty set literal
        (which cannot appear in Python source: {} is a dictionary)

diff --git a/pypy/interpreter/astcompiler/codegen.py 
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -904,8 +904,9 @@
 
     def visit_Set(self, s):
         self.update_position(s.lineno)
+        elt_count = len(s.elts) if s.elts is not None else 0
         self.visit_sequence(s.elts)
-        self.emit_op_arg(ops.BUILD_SET, len(s.elts))
+        self.emit_op_arg(ops.BUILD_SET, elt_count)
 
     def visit_Name(self, name):
         self.update_position(name.lineno)
diff --git a/pypy/module/_ast/test/test_ast.py 
b/pypy/module/_ast/test/test_ast.py
--- a/pypy/module/_ast/test/test_ast.py
+++ b/pypy/module/_ast/test/test_ast.py
@@ -290,6 +290,12 @@
         ])
         exec compile(body, '<string>', 'exec')
 
+    def test_empty_set(self):
+        import ast
+        m = ast.Module(body=[ast.Expr(value=ast.Set(elts=[]))])
+        ast.fix_missing_locations(m)
+        compile(m, "<test>", "exec")
+
     def test_invalid_sum(self):
         import _ast as ast
         pos = dict(lineno=2, col_offset=3)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to