tree-sitter-c-sharp icon indicating copy to clipboard operation
tree-sitter-c-sharp copied to clipboard

Precedence incorrect between or and conditional access

Open Sjord opened this issue 3 years ago • 2 comments

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])))))))

Sjord avatar Sep 14 '22 10:09 Sjord

I think this one is also related to #172

damieng avatar Sep 15 '22 08:09 damieng

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))))))))))

Sjord avatar Jan 15 '24 13:01 Sjord