tree-sitter / tree-sitter/tree-sitter-cpp

bug: wrong parse tree for new array of pointers

Open
#289 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
453
Forks
185
PR merge metrics
No merged PRs in 30d

Description

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

Currently parsing of:
int** arrayOfPointers = new int*[10];
is wrong.
Since declarator can only be new_declarator and not a list of declarators which one of them is new_declarator

Steps To Reproduce/Bad Parse Tree

declaration [0, 0] - [0, 37]
type: primitive_type [0, 0] - [0, 3]
declarator: init_declarator [0, 3] - [0, 31]
declarator: pointer_declarator [0, 3] - [0, 21]
declarator: pointer_declarator [0, 4] - [0, 21]
declarator: identifier [0, 6] - [0, 21]
value: new_expression [0, 24] - [0, 31]
type: primitive_type [0, 28] - [0, 31]
ERROR [0, 31] - [0, 36]
lambda_capture_specifier [0, 32] - [0, 36]
number_literal [0, 33] - [0, 35]

Expected Behavior/Parse Tree

Maybe add more declarators for new_expression besides new_declarator?

Repro
int** arrayOfPointers = new int*[10];

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reported repro, int** arrayOfPointers = new int*[10];, with the tree-sitter-cpp parser and compare its tree with the expected C++ structure. Read the grammar rules involved in new_expression, new_declarator, and declarators; done means the array-of-pointers expression parses without the reported ERROR node.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.