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

bug: Member Variables Declarations Using Equal-Initializer Parsed As Function Definitions #273

Closed
2 tasks done
savantes1 opened this issue Jun 28, 2024 · 0 comments · Fixed by #286
Closed
2 tasks done
Labels

Comments

@savantes1
Copy link

savantes1 commented Jun 28, 2024

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • I have searched the existing issues of tree-sitter-cpp

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

tree-sitter 0.22.3, tree-sitter-cpp 0.22.2

Describe the bug

Member variables that are initialized using the equal-initializer syntax (e.g., int x = 0;) show up in the tree as type function_definition rather than type field_declaration , as is the case when member variables are uninitialized or brace-initialized.

Steps To Reproduce/Bad Parse Tree

If you parse the following custom data type:

struct A
{
    int x = 0;
    int y{0};
    int z;

    void func() {}
};

You get the following parse tree:

(translation_unit 
    (struct_specifier 
        name: (type_identifier) 
        body: (field_declaration_list
            (function_definition 
                type: (primitive_type)
                declarator: (field_identifier)
                (pure_virtual_clause)
            )
            (field_declaration 
                type: (primitive_type)
                declarator: (field_identifier) 
                default_value: (initializer_list 
                    (number_literal)
                )
            ) 
            (field_declaration 
                type: (primitive_type) 
                declarator: (field_identifier)
            ) 
            (function_definition 
                type: (primitive_type) 
                declarator: (function_declarator 
                    declarator: (field_identifier) 
                    parameters: (parameter_list)
                ) 
                body: (compound_statement)
            )
        )
    )
)

Expected Behavior/Parse Tree

(translation_unit 
    (struct_specifier 
        name: (type_identifier) 
        body: (field_declaration_list
            (field_declaration 
                type: (primitive_type)
                declarator: (field_identifier)
                (default_value: (initializer_list
                   (number_literal)
            ) 
            (field_declaration 
                type: (primitive_type)
                declarator: (field_identifier) 
                default_value: (initializer_list 
                    (number_literal)
                )
            ) 
            (field_declaration 
                type: (primitive_type) 
                declarator: (field_identifier)
            ) 
            (function_definition 
                type: (primitive_type) 
                declarator: (function_declarator 
                    declarator: (field_identifier) 
                    parameters: (parameter_list)
                ) 
                body: (compound_statement)
            )
        )
    )
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant