tree-sitter/tree-sitter-c-sharp

Precedence incorrect between or and conditional access

Sjord opened this issue · 2 comments

Sjord commented
x || x?.C;

Parsed as (x || x)?.C instead of x || (x?.C).

Actual:

(compilation_unit [0, 0] - [1, 0]
  (global_statement [0, 0] - [0, 10]
    (expression_statement [0, 0] - [0, 10]
      (conditional_access_expression [0, 0] - [0, 9]
        condition: (binary_expression [0, 0] - [0, 6]
          left: (identifier [0, 0] - [0, 1])
          right: (identifier [0, 5] - [0, 6]))
        (member_binding_expression [0, 7] - [0, 9]
          name: (identifier [0, 8] - [0, 9]))))))

Expected:

(compilation_unit [0, 0] - [1, 0]
  (global_statement [0, 0] - [0, 11]
    (expression_statement [0, 0] - [0, 11]
      (binary_expression [0, 0] - [0, 10]
        left: (identifier [0, 0] - [0, 1])
        right: (conditional_access_expression [0, 5] - [0, 9]
            condition: (identifier [0, 5] - [0, 6])
            (member_binding_expression [0, 7] - [0, 9]
              name: (identifier [0, 8] - [0, 9])))))))

I think this one is also related to #172

Test case:

=====================================
Precedence between or and conditional access
=====================================

var a = x || x?.C;

---

(compilation_unit
  (global_statement
    (local_declaration_statement
      (variable_declaration
        type: (implicit_type)
        (variable_declarator
          name: (identifier)
          (equals_value_clause
             (binary_expression
               left: (identifier)
               right: (conditional_access_expression
                   condition: (identifier)
                   (member_binding_expression
                     name: (identifier))))))))))