bug: braced default argument (= {}) in a parameter list is an ERROR
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 84/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript
- 領域
- compilers
調査の方向性
issue では、optional_parameter_declaration が default_value に対して式しか受け付けないことを指摘し、initializer_list を受け付ける近くの例として init_declarator を挙げています。それらの文法規則を読み、次に repro の3つの宣言を tree-sitter で解析して、現在のエラーを確認してください。3つのデフォルトの波括弧リストすべてが、エラーなく 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
-
xsd:integer cast from a string rejects negative numbers, a leading + and surrounding whitespaceオープンbug 🐛
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
comunica/comunica#1960 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Waiting for: Product Owner
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
getsentry/sentry-javascript#26203 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
bytedance/flowgram.ai#1235 ·
メンテナーはふだん 1 日以内に返信