[pypy-svn] r45274 - in pypy/dist/pypy/tool: . test

fijal at codespeak.net fijal at codespeak.net
Mon Jul 23 15:13:26 CEST 2007


Author: fijal
Date: Mon Jul 23 15:13:25 2007
New Revision: 45274

Modified:
   pypy/dist/pypy/tool/error.py
   pypy/dist/pypy/tool/test/test_error.py
Log:
Improve error reporting when SomeObject comes from a simple_call,
by listing all functions involved and they're return value annotations.


Modified: pypy/dist/pypy/tool/error.py
==============================================================================
--- pypy/dist/pypy/tool/error.py	(original)
+++ pypy/dist/pypy/tool/error.py	Mon Jul 23 15:13:25 2007
@@ -111,7 +111,18 @@
     for block, graph in blocked_blocks.items():
         text.append(gather_error(annotator, block, graph))
     return '\n'.join(text)
-    
+
+def format_simple_call(annotator, oper, what, msg):
+    msg.append("Simple call of incompatible family:")
+    descs = annotator.bindings[oper.args[0]].descriptions
+    for desc in descs.keys():
+        func = desc.pyobj
+        msg.append("  function %s <%s, line %s> returning" % (func.func_name,
+                   func.func_code.co_filename, func.func_code.co_firstlineno))
+        graph = desc.getuniquegraph()
+        msg.append("      %s" % annotator.bindings[graph.returnblock.inputargs[0]])
+        msg.append("")
+
 def format_someobject_error(annotator, position_key, what, s_value, called_from_graph, binding=""):
     #block = getattr(annotator, 'flowin_block', None) or block
     msg = ["annotation of %r degenerated to SomeObject()" % (what,)]
@@ -119,7 +130,10 @@
         graph, block, operindex = position_key
         if operindex is not None:
             oper = block.operations[operindex]
-            msg.append(str(oper))
+            if oper.opname == 'simple_call':
+                format_simple_call(annotator, oper, what, msg)
+            else:
+                msg.append(str(oper))
         else:
             msg.append("at the start of the block with input arguments:")
             for v in block.inputargs:

Modified: pypy/dist/pypy/tool/test/test_error.py
==============================================================================
--- pypy/dist/pypy/tool/test/test_error.py	(original)
+++ pypy/dist/pypy/tool/test/test_error.py	Mon Jul 23 15:13:25 2007
@@ -84,3 +84,23 @@
         return A().g()
 
     py.test.raises(NoSuchAttrError, compile_function, g, [])
+
+def test_someobject_from_call():
+    def one(x):
+        return str(x)
+
+    def two(x):
+        return int(x)
+
+    def fn(n):
+        if n:
+            to_call = one
+        else:
+            to_call = two
+        return to_call(n)
+
+    try:
+        compile_function(fn, [int])
+    except AnnotatorError, e:
+        assert 'function one' in e.args[0]
+        assert 'function two' in e.args[0]



More information about the Pypy-commit mailing list