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: declaration of function pointer not handling correctly functions without arguments #281

Open
2 tasks done
uriyay-jfrog opened this issue Aug 4, 2024 · 0 comments
Open
2 tasks done
Labels

Comments

@uriyay-jfrog
Copy link

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)

No response

Describe the bug

Function declarator without any parameters is not parsed correctly in tree-sitter-cpp:

void (*func_t)() = NULL;

Output from the playground:

translation_unit [0, 0] - [6, 0]
  expression_statement [0, 0] - [0, 24]
    assignment_expression [0, 0] - [0, 23]
      left: call_expression [0, 0] - [0, 16]
        function: call_expression [0, 0] - [0, 14]
          function: primitive_type [0, 0] - [0, 4]
          arguments: argument_list [0, 5] - [0, 14]
            pointer_expression [0, 6] - [0, 13]
              argument: identifier [0, 7] - [0, 13]
        arguments: argument_list [0, 14] - [0, 16]
      right: null [0, 19] - [0, 23]

The parser for some reason treats it as an assignment with call expression as the left side.

While tree-sitter-c parses it correctly:

translation_unit [0, 0] - [6, 0]
  declaration [0, 0] - [0, 24]
    type: primitive_type [0, 0] - [0, 4]
    declarator: init_declarator [0, 5] - [0, 23]
      declarator: function_declarator [0, 5] - [0, 16]
        declarator: parenthesized_declarator [0, 5] - [0, 14]
          pointer_declarator [0, 6] - [0, 13]
            declarator: identifier [0, 7] - [0, 13]
        parameters: parameter_list [0, 14] - [0, 16]
      value: null [0, 19] - [0, 23]

Steps To Reproduce/Bad Parse Tree

translation_unit [0, 0] - [6, 0]
  expression_statement [0, 0] - [0, 24]
    assignment_expression [0, 0] - [0, 23]
      left: call_expression [0, 0] - [0, 16]
        function: call_expression [0, 0] - [0, 14]
          function: primitive_type [0, 0] - [0, 4]
          arguments: argument_list [0, 5] - [0, 14]
            pointer_expression [0, 6] - [0, 13]
              argument: identifier [0, 7] - [0, 13]
        arguments: argument_list [0, 14] - [0, 16]
      right: null [0, 19] - [0, 23]

Expected Behavior/Parse Tree

translation_unit [0, 0] - [6, 0]
  declaration [0, 0] - [0, 24]
    type: primitive_type [0, 0] - [0, 4]
    declarator: init_declarator [0, 5] - [0, 23]
      declarator: function_declarator [0, 5] - [0, 16]
        declarator: parenthesized_declarator [0, 5] - [0, 14]
          pointer_declarator [0, 6] - [0, 13]
            declarator: identifier [0, 7] - [0, 13]
        parameters: parameter_list [0, 14] - [0, 16]
      value: null [0, 19] - [0, 23]

Repro

void (*func_t)() = NULL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant