bug: braced default argument (= {}) in a parameter list is an ERROR
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 84/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript
- 领域
- compilers
调研方向
Issue 指出 optional_parameter_declaration 对 default_value 只接受表达式,并以附近接受 initializer_list 的 init_declarator 为例。阅读这些语法规则,然后用 tree-sitter 解析 repro 中的三个声明,以确认当前的错误。当三个默认花括号列表都能作为 initializer_list 解析且没有错误时,任务即告完成。
由索引模型根据 Issue 内容生成。
描述
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
A default argument written as a braced initializer list, valid since C++11 ([dcl.fct.default] allows an initializer-clause, which includes a braced-init-list), makes the tree contain an error. The default value is recovered as a compound_literal_expression with a MISSING type_identifier, so has_error is true for the whole file.
This is common in modern code (Options = {}, std::vector v = {1, 2}). In one C++20 project it was the most frequent cause of parse errors: 16 of 131 files failed only because of it.
optional_parameter_declaration accepts only an expression as default_value, both in v0.23.4 and on master (c009222), while init_declarator already accepts initializer_list.
Steps To Reproduce/Bad Parse Tree
Save the repro below as repro.cpp.
Run tree-sitter parse repro.cpp, or parse it with any binding.
Parse tree from tree-sitter-cpp 0.23.4 (named nodes only), first declaration:
translation_unit
declaration
type: primitive_type
declarator: function_declarator
declarator: identifier
parameters: parameter_list
optional_parameter_declaration
type: primitive_type
declarator: identifier
default_value: compound_literal_expression
type: type_identifier (MISSING)
value: initializer_list
The other two declarations give the same compound_literal_expression with a MISSING type_identifier.
Expected Behavior/Parse Tree
No error; the braced list is the default value:
optional_parameter_declaration
type: primitive_type
declarator: identifier
default_value: initializer_list
A possible fix is field('default_value', choice($.expression, $.initializer_list)) in optional_parameter_declaration, as init_declarator does for its value.
Repro
void f(int x = {});
void g(std::vector<int> v = {1, 2});
struct Options {};
void h(Options = {});
- 主要语言
- JavaScript
- 星标
- 463
- 派生
- 196
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
tree-sitter/tree-sitter-cpp 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
tree-sitter/tree-sitter-cpp#374 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
tree-sitter/tree-sitter-cpp#371 · 1 条评论 ·
-
`tree_sitter_cpp_external_scanner_deserialize` doesn't bound `length` against the size of the delimiter buffer可能已有人在做 @dekobon 于 96 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
tree-sitter/tree-sitter-cpp#368 ·
-
bug
难度 3/5 1-2 天 新手友好度 62/100
tree-sitter/tree-sitter-cpp#378 ·
-
bug
难度 3/5 1-2 天 新手友好度 70/100
tree-sitter/tree-sitter-cpp#377 · 1 条评论 ·
查看 tree-sitter/tree-sitter-cpp 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 75/100
postcss/postcss.org#302 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
ImranR98/apps.obtainium.imranr.dev#2000 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
-
难度 2/5 1-3 小时 新手友好度 83/100
microsoft/monaco-editor#5577 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
Ebony-Vinyl/dsh-our-free-model#785 ·
维护者通常 1 天内回复