bug: #ifdef causes "else" to be treated as error
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start by loading the provided C++ reproduction in the Tree-sitter Playground (0.23.4?) and compare its bad parse tree with the expected behavior. Trace how preproc_ifdef and if_statement interact around the conditional else; done means the reproduction no longer marks else as ERROR and the resulting tree preserves the intended branches.
Written by the indexing model from the issue text.
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)
Playground (0.23.4?)
Describe the bug
When "interrupting" an if/else with an #ifdef then the else is treated as an error. This might be tricky to turn into a proper tree, as the "ifdef" can separate the "else" branch content from the "if".
Steps To Reproduce/Bad Parse Tree
translation_unit [0, 0] - [6, 0]
preproc_ifdef [0, 0] - [4, 6]
name: identifier [0, 7] - [0, 20]
if_statement [1, 1] - [2, 8]
condition: condition_clause [1, 4] - [1, 9]
value: identifier [1, 5] - [1, 8]
consequence: expression_statement [2, 2] - [2, 8]
call_expression [2, 2] - [2, 7]
function: identifier [2, 2] - [2, 5]
arguments: argument_list [2, 5] - [2, 7]
ERROR [3, 1] - [3, 5]
expression_statement [5, 2] - [5, 8]
call_expression [5, 2] - [5, 7]
function: identifier [5, 2] - [5, 5]
arguments: argument_list [5, 5] - [5, 7]
Expected Behavior/Parse Tree
A solution might be difficult to do with the current structure. Here's a workaround that would preserve the logic and could be supported with the current structure. Maybe it could be treated like that automatically?
#ifdef DO_THIS_CHECK
if (bar)
baz();
else
qux();
#else
qux();
#endif
Repro
#ifdef DO_THIS_CHECK
if (bar)
baz();
else
#endif
qux();
- Dominant language
- JavaScript
- Stars
- 453
- Forks
- 185
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tree-sitter/tree-sitter-cpp
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
tree-sitter/tree-sitter-cpp#371 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
tree-sitter/tree-sitter-cpp#368 ·
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 45/100
tree-sitter/tree-sitter-cpp#365 · 1 reaction ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 45/100
tree-sitter/tree-sitter-cpp#363 ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
tree-sitter/tree-sitter-cpp#359 ·
All issues in tree-sitter/tree-sitter-cpp
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·