Skip to content

[BUG] Compiler crash attempting construction with named initialisation #7206

@CypherGrue

Description

@CypherGrue

Describe the bug

Probably shouldn't compile, but probably shouldn't crash too.

Code to reproduce the behaviour:

# distutils: language=c++
cdef extern from *:
    """
    class C {
        public:
            int i;
            C() : i(0) {}
            C(int j) : i(j) {}
    };
    """

    cdef cppclass C:
        int i
        C()
        C(int j)

cdef C c = C(i=0)
Error compiling Cython file:
------------------------------------------------------------
...
    """

    cdef cppclass C:
        int i

cdef C c = C(i=0)
            ^
------------------------------------------------------------

wtf.pyx:13:12: Compiler crash in AnalyseExpressionsTransform

File 'Nodes.py', line 409, in analyse_expressions: StatListNode(wtf.pyx:2:0)
File 'Nodes.py', line 6150, in analyse_expressions: SingleAssignmentNode(wtf.pyx:13:0)
File 'Nodes.py', line 6283, in analyse_types: SingleAssignmentNode(wtf.pyx:13:0)
File 'ExprNodes.py', line 7180, in analyse_types: GeneralCallNode(wtf.pyx:13:12,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 6068, in analyse_as_type_constructor: GeneralCallNode(wtf.pyx:13:12,
    result_is_used = True,
    use_managed_ref = True)

Compiler crash traceback from this point on:
  File "/usr/local/lib/python3.13/dist-packages/Cython/Compiler/ExprNodes.py", line 6068, in analyse_as_type_constructor
    self.args = [ arg.analyse_types(env) for arg in self.args ]
                                                    ^^^^^^^^^
AttributeError: 'GeneralCallNode' object has no attribute 'args'

Expected behaviour

An error describing the problem (e.g. "C++ constructor got unexpected keyword argument"), rather than a compiler crash

OS

Linux

Python version

3.13.3

Cython version

3.0.11 and 3.1.4

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions