PyPy crashes when using slicing to retrieve a new list
The given code defines a class X with a special method index, in which the code deletes all the elements in the global list a by using the del statement. Then, it returns the integer 1. After that, the code creates a list a with a single element 0. Finally, the code uses slicing to retrieve a new list that starts from the beginning of the a list, ends at the end of the list (implicitly), and selects every other element. On CPython, this test can work normal, while it trigger a crash on PyPy.
test.py
class X:
def __index__(self):
del a[:]
return 1
a = [0]
a[:X():2]
The actual output on PyPy:
RPython traceback:
File "pypy_interpreter_1.c", line 40152, in execute_frame
File "rpython_jit_metainterp.c", line 7591, in ll_portal_runner__Unsigned_Bool_pypy_interpreter
File "pypy_module_pypyjit.c", line 941, in portal_11
File "pypy_interpreter_2.c", line 42779, in handle_bytecode__AccessDirect_None
File "pypy_interpreter_3.c", line 19015, in dispatch_bytecode__AccessDirect_None
File "pypy_objspace_std_9.c", line 3632, in list_BINARY_SUBSCR__AccessDirect_None
File "implement.c", line 42247, in W_ListObject_shortcut___getitem__
File "pypy_objspace_std_1.c", line 16648, in W_ListObject_descr_getitem
File "pypy_objspace_std_4.c", line 32888, in IntegerListStrategy_getslice
File "pypy_objspace_std_5.c", line 31327, in IntegerListStrategy__fill_in_with_sliced_items
Traceback (most recent call last):
File "/home/xxm/Desktop/pypy/test.py", line 784, in <module>
a[:X():2]
SystemError: unexpected internal exception (please report a bug): <IndexError object at 0x7f845cf0a128>; internal traceback was dumped to stderr
Reproduce step:
- download the binaries from https://www.pypy.org/download.html
- 'pypy3.9-v7.3.11-linux64/bin/pypy3.9' test.py
Environment: Ubuntu 18.04; PyPy:pypy3.9-v7.3.11-linux64; CPython: 3.11.3