bug: braced default argument (= {}) in a parameter list is an ERROR
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 84/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript
- Lĩnh vực
- compilers
Hướng nghiên cứu
Issue chỉ ra rằng optional_parameter_declaration chỉ chấp nhận một biểu thức cho default_value và nêu init_declarator làm ví dụ gần đó có chấp nhận initializer_list. Hãy đọc các quy tắc ngữ pháp đó, sau đó phân tích ba khai báo trong repro bằng tree-sitter để xác nhận các lỗi hiện tại. Công việc hoàn tất khi cả ba danh sách mặc định đặt trong ngoặc nhọn đều được phân tích thành initializer_list mà không có lỗi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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 = {});
- Ngôn ngữ chính
- JavaScript
- Star
- 463
- Fork
- 196
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của tree-sitter/tree-sitter-cpp
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
tree-sitter/tree-sitter-cpp#374 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
tree-sitter/tree-sitter-cpp#371 · 1 bình luận ·
-
`tree_sitter_cpp_external_scanner_deserialize` doesn't bound `length` against the size of the delimiter bufferCó thể đã có người làm @dekobon đã nhận 96 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
tree-sitter/tree-sitter-cpp#368 ·
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
tree-sitter/tree-sitter-cpp#378 ·
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 70/100
tree-sitter/tree-sitter-cpp#377 · 1 bình luận ·
Tất cả issue của tree-sitter/tree-sitter-cpp
Issue tương tự
-
xsd:integer cast from a string rejects negative numbers, a leading + and surrounding whitespaceĐang mởbug 🐛
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
comunica/comunica#1960 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Waiting for: Product Owner
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
getsentry/sentry-javascript#26203 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
bytedance/flowgram.ai#1235 ·
Maintainer thường phản hồi trong vòng 1 ngày