Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutually referencing templates crash with AttributeError: 'NoneType' object has no attribute 'specialize' #2892

dgrunwald opened this Issue Mar 13, 2019 · 0 comments


None yet
2 participants
Copy link

dgrunwald commented Mar 13, 2019

Reduced test case:

cdef extern from "header.h" nogil:
    cppclass Iterator[T1]  # forward decl

    cppclass Container[T2]:
        ctypedef Iterator[T2] iterator

    cppclass Iterator[T1]:
        Container[T1]* container
        int index

Compiling this with cython 0.29.6 results in a crash:

cpplib.pxd:5:26: Compiler crash in AnalyseDeclarationsTransform

File '', line 124, in analyse_declarations: ModuleNode(cpplib.pxd:1:0,
    full_module_name = u'cpplib',
    is_pxd = True)
File '', line 431, in analyse_declarations: StatListNode(cpplib.pxd:1:5)
File '', line 486, in analyse_declarations: CDefExternNode(cpplib.pxd:1:5,
    include_file = u'header.h')
File '', line 431, in analyse_declarations: StatListNode(cpplib.pxd:2:4)
File '', line 1506, in analyse_declarations: CppClassNode(cpplib.pxd:4:4,
    base_classes = [...]/0,
    in_pxd = True,
    name = u'Container',
    templates = [...]/1)
File '', line 1610, in analyse_declarations: CTypeDefNode(cpplib.pxd:5:8)
File '', line 1160, in analyse: TemplatedTypeNode(cpplib.pxd:5:26)

Compiler crash traceback from this point on:
  File "c:\python27-x86\lib\site-packages\Cython\Compiler\", line 1160, in analyse
    self.type = base_type.specialize_here(self.pos, template_types)
  File "c:\python27-x86\lib\site-packages\Cython\Compiler\", line 3677, in specialize_here
    return self.specialize(dict(zip(self.templates, template_values)))
  File "c:\python27-x86\lib\site-packages\Cython\Compiler\", line 3695, in specialize
    specialized.scope = self.scope.specialize(values, specialized)
AttributeError: 'NoneType' object has no attribute 'specialize'

The Container[T1]* container member in Iterator is not necessary to reproduce this problem; it just shows that there's no easy workaround by re-ordering the members.
Interestingly, while reducing the test case, I found that the crash does not happen if the two classes use the same name for their type parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.