SystemError for pep695 type parameter with the same name as the inner class · Issue #109219 · python/cpython (original) (raw)

Bug report

Bug description:

The following script shows the SystemError:

class name_1[name_4]:

class name_4[name_2](name_4):
    name_4

output (Python 3.12.0rc2+):

SystemError: compiler_lookup_arg(name='name_4') with reftype=3 failed in ; freevars of code name_4: ('.type_params', 'name_4')

minimizing it further leads some different crashes:
The propably most interresting one is this, which does not look special at all.

class name_1[name_3]: class name_4name_2: pass

output (Python 3.12.0rc2+):

Traceback (most recent call last): File "/home/frank/projects/pysource-codegen/bug3.py", line 1, in class name_1[name_3]: File "/home/frank/projects/pysource-codegen/bug3.py", line 1, in class name_1[name_3]: File "/home/frank/projects/pysource-codegen/bug3.py", line 2, in name_1 class name_4name_2: File "/home/frank/projects/pysource-codegen/bug3.py", line 2, in class name_4name_2: ^^^^^^ NameError: name 'name_5' is not defined. Did you mean: 'name_2'? Modules/gcmodule.c:113: gc_decref: Assertion "gc_get_refs(g) > 0" failed: refcount is too small Enable tracemalloc to get the memory block allocation traceback

object address : 0x7f2c57a12930 object refcount : 1 object type : 0x557ad9ef1fe0 object type name: dict object repr : {'module': 'main', 'qualname': 'name_1', 'type_params': (name_3,)}

Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed Python runtime state: finalizing (tstate=0x0000557ada04eba0)

Current thread 0x00007f2c57f21280 (most recent call first): Garbage-collecting

@JelleZijlstra I think this is another one for you. Feel free to create a second issue if you think that they are unrelated.

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs