Skip to content

[BUG] Type with a member that has initializer and defined operator=: (out this, n : std::name ) produces an assignment operator that badly assign member with initializer #291

@filipsajdak

Description

@filipsajdak

In the current implementation of cppfront (fbf55ad) the following code:

element: type = {
    children: std::vector<int> = ();
    name: std::string;

    operator=: (out this, n : std::string ) = {
        name = n;
    }
}

Generates:

#include "cpp2util.h"


#line 1 "/Users/filipsajdak/dev/execspec/external/tests/bug_assignement_operator_2.cpp2"
class element;

//=== Cpp2 definitions ==========================================================

#line 1 "/Users/filipsajdak/dev/execspec/external/tests/bug_assignement_operator_2.cpp2"
class element  {
    private: std::vector<int> children {}; 
    private: std::string name; 

    public: explicit element(cpp2::in<std::string> n)
        : name{ n }
#line 6 "/Users/filipsajdak/dev/execspec/external/tests/bug_assignement_operator_2.cpp2"
{
    }
#line 5 "/Users/filipsajdak/dev/execspec/external/tests/bug_assignement_operator_2.cpp2"
    public: auto operator=(cpp2::in<std::string> n) -> element& {
        children = ;
        name = n;
#line 6 "/Users/filipsajdak/dev/execspec/external/tests/bug_assignement_operator_2.cpp2"
        
        return *this;
#line 7 "/Users/filipsajdak/dev/execspec/external/tests/bug_assignement_operator_2.cpp2"
    }
};

The issue is that the assignment operator has one assignment to the children variable that is not complete:

        children = ;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions