-
-
Notifications
You must be signed in to change notification settings - Fork 142
Open
Labels
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)
the latest used at https://tree-sitter.github.io/tree-sitter/7-playground.html
Describe the bug
A conversion operator is sometimes misinterpreted as a regular function with a weird (broken) return type, as opposed to operator_cast.
Steps To Reproduce/Bad Parse Tree
function_definition [0, 0] - [2, 1]
storage_class_specifier [0, 0] - [0, 6]
type: qualified_identifier [0, 7] - [0, 18]
scope: namespace_identifier [0, 7] - [0, 8]
name: type_identifier [0, 10] - [0, 18]
declarator: function_declarator [0, 19] - [0, 24]
declarator: identifier [0, 19] - [0, 22]
parameters: parameter_list [0, 22] - [0, 24]
body: compound_statement [0, 25] - [2, 1]
return_statement [1, 2] - [1, 12]
number_literal [1, 9] - [1, 11]
Which is incorrect since it treats this as a function called int with the A::operator return type.
Expected Behavior/Parse Tree
Removing inline in this example results in a correct parsing:
function_definition [0, 0] - [2, 1]
declarator: qualified_identifier [0, 0] - [0, 17]
scope: namespace_identifier [0, 0] - [0, 1]
name: operator_cast [0, 3] - [0, 17]
type: primitive_type [0, 12] - [0, 15]
declarator: abstract_function_declarator [0, 15] - [0, 17]
parameters: parameter_list [0, 15] - [0, 17]
body: compound_statement [0, 18] - [2, 1]
return_statement [1, 2] - [1, 12]
number_literal [1, 9] - [1, 11]
Repro
inline A::operator int() {
return 42;
}