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

Incorrect test for conditional access expression with simple member access

Open Sjord opened this issue 4 years ago • 1 comments

The test in expressions.txt is incorrect:

=====================================
Conditional access expression with simple member access
=====================================

if ((p as Person[])?[0]._Age != 1) { }

---

(compilation_unit
  (global_statement
    (if_statement
      (binary_expression
          (member_access_expression
            (conditional_access_expression
              (parenthesized_expression
                (as_expression (identifier) (array_type (identifier) (array_rank_specifier))))
              (element_binding_expression
                (bracketed_argument_list (argument (integer_literal)))))
            (identifier))
          (integer_literal))
      (block))))

Actual: The member_access_expression evaluates .Age on a conditional_access_expression, whose value is possibly null.

Expected: The evaluation of .Age is only performed if (p as Person[]) is not null. The member_access_expression should be inside the conditional_access_expression.

Sjord avatar Mar 25 '21 19:03 Sjord

See also #131. This comment seems to have a correct test.

Sjord avatar Mar 27 '21 12:03 Sjord