[pypy-issue] Issue #2011: RPython: Better error message for obvious type errors (pypy/pypy)
Ronan Lamy
issues-reply at bitbucket.org
Wed Mar 25 01:52:18 CET 2015
New issue 2011: RPython: Better error message for obvious type errors
https://bitbucket.org/pypy/pypy/issue/2011/rpython-better-error-message-for-obvious
Ronan Lamy:
Consider this code:
```
#!python
def entry_point(argv):
print len([0, 1][0])
return 0
def target(*args):
return entry_point, None
```
Currently, translating it fails with
```
[translation:ERROR] MissingRTypeOperation: unimplemented operation: 'len' on <IntegerRepr Signed>
[translation:ERROR] .. (targ:1)entry_point
[translation:ERROR] .. block at 9 with 1 exits
[translation:ERROR] .. v28 = len(v27)
```
which tends to confuse users. The problem, calling `len()` on an int, could easily be detected during annotation. If we raised an AnnotationError, we could have a much nicer error message, for instance:
```
[translation:ERROR] AnnotatorError:
[translation:ERROR]
[translation:ERROR] Object has no len()
[translation:ERROR]
[translation:ERROR]
[translation:ERROR] v1 = len(v0)
[translation:ERROR]
[translation:ERROR] In <FunctionGraph of (targ:1)entry_point at 0x2bbb0d0>:
[translation:ERROR] Happened at file targ.py line 2
[translation:ERROR]
[translation:ERROR] ==> print len([0, 1][0])
[translation:ERROR]
[translation:ERROR] Known variable annotations:
[translation:ERROR] v0 = SomeInteger(knowntype=int, nonneg=True, unsigned=False)
[translation:ERROR]
[translation:ERROR] Processing block:
[translation:ERROR] block at 9 is a <class 'rpython.flowspace.flowcontext.SpamBlock'>
[translation:ERROR] in (targ:1)entry_point
[translation:ERROR] containing the following operations:
[translation:ERROR] v2 = newlist((0), (1))
[translation:ERROR] v0 = getitem(v2, (0))
[translation:ERROR] v1 = len(v0)
[translation:ERROR] v3 = str(v1)
[translation:ERROR] v4 = simple_call((function rpython_print_item), v3)
[translation:ERROR] v5 = simple_call((function rpython_print_newline))
[translation:ERROR] --end--
```
Note that `len()` is just an example, there are many similar cases, including those where the error message is the dreaded "Blocked block -- operation cannot succeed" instead of MissingRTypeOperation.
More information about the pypy-issue
mailing list