Commits

Armin Rigo committed 2a140ba

Fix len(None) to return SomeImpossibleValue, which, if the None is never
generalized, ends up in a blocked block.

  • Participants
  • Parent commits 113bc72

Comments (0)

Files changed (2)

rpython/annotator/test/test_annrpython.py

         assert isinstance(s, annmodel.SomeTuple)
         assert s.items[1].const == 42
 
+    def test_unpack_none_gets_a_blocked_block(self):
+        def f(x):
+            a, b = x
+        a = self.RPythonAnnotator()
+        py.test.raises(annmodel.AnnotatorError,
+                       a.build_types, f, [annmodel.s_None])
+
 
 def g(n):
     return [0, 1, 2, n]

rpython/annotator/unaryop.py

         s.const = False
 
     def len(self):
-        # XXX: this None could later be generalized into an empty list,
-        # whose length is the constant 0; so let's tentatively answer 0.
-        return immutablevalue(0)
+        # This None could later be generalized into a list, for example.
+        # For now, we give the impossible answer (because len(None) would
+        # really crash translated code).  It can be generalized later.
+        return SomeImpossibleValue()
 
 #_________________________________________
 # weakrefs