tree-sitter / tree-sitter-c-sharp

C# Grammar for tree-sitter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Argument modifier in lambda gives parse error

Sjord opened this issue · comments

E.g.

using System;

class LambdaRef
{
    private delegate int MyIntDelegate(ref int i);
    
    public static void Main()
    {
        MyIntDelegate a = (ref int i) => i + 1;
        var orig = 3;
        Console.WriteLine(a(ref orig));
    }
}

Expected:

(compilation_unit [0, 3] - [12, 1]
  (using_directive [0, 3] - [0, 16]
    (identifier [0, 9] - [0, 15]))
  (class_declaration [2, 0] - [12, 1]
    name: (identifier [2, 6] - [2, 15])
    body: (declaration_list [3, 0] - [12, 1]
      (delegate_declaration [4, 4] - [4, 50]
        (modifier [4, 4] - [4, 11])
        type: (predefined_type [4, 21] - [4, 24])
        name: (identifier [4, 25] - [4, 38])
        parameters: (parameter_list [4, 38] - [4, 49]
          (parameter [4, 43] - [4, 48]
            type: (predefined_type [4, 43] - [4, 46])
            name: (identifier [4, 47] - [4, 48]))))
      (method_declaration [6, 4] - [11, 5]
        (modifier [6, 4] - [6, 10])
        (modifier [6, 11] - [6, 17])
        type: (void_keyword [6, 18] - [6, 22])
        name: (identifier [6, 23] - [6, 27])
        parameters: (parameter_list [6, 27] - [6, 29])
        body: (block [7, 4] - [11, 5]
          (local_declaration_statement [8, 8] - [8, 47]
            (variable_declaration [8, 8] - [8, 46]
              type: (identifier [8, 8] - [8, 21])
              (variable_declarator [8, 22] - [8, 46]
                (identifier [8, 22] - [8, 23])
                (equals_value_clause [8, 24] - [8, 46]
                  (lambda_expression [8, 26] - [8, 46]
                    (parameter_list [8, 26] - [8, 37]
                      (parameter [8, 31] - [8, 36]
                        type: (predefined_type [8, 31] - [8, 34])
                        name: (identifier [8, 35] - [8, 36])))
                    body: (binary_expression [8, 41] - [8, 46]
                      left: (identifier [8, 41] - [8, 42])
                      right: (integer_literal [8, 45] - [8, 46])))))))
          (local_declaration_statement [9, 8] - [9, 21]
            (variable_declaration [9, 8] - [9, 20]
              type: (implicit_type [9, 8] - [9, 11])
              (variable_declarator [9, 12] - [9, 20]
                (identifier [9, 12] - [9, 16])
                (equals_value_clause [9, 17] - [9, 20]
                  (integer_literal [9, 19] - [9, 20])))))
          (expression_statement [10, 8] - [10, 39]
            (invocation_expression [10, 8] - [10, 38]
              function: (member_access_expression [10, 8] - [10, 25]
                expression: (identifier [10, 8] - [10, 15])
                name: (identifier [10, 16] - [10, 25]))
              arguments: (argument_list [10, 25] - [10, 38]
                (argument [10, 26] - [10, 37]
                  (invocation_expression [10, 26] - [10, 37]
                    function: (identifier [10, 26] - [10, 27])
                    arguments: (argument_list [10, 27] - [10, 37]
                      (argument [10, 32] - [10, 36]
                        (identifier [10, 32] - [10, 36])))))))))))))

Actual:

(compilation_unit [0, 3] - [12, 1]
  (using_directive [0, 3] - [0, 16]
    (identifier [0, 9] - [0, 15]))
  (class_declaration [2, 0] - [12, 1]
    name: (identifier [2, 6] - [2, 15])
    body: (declaration_list [3, 0] - [12, 1]
      (delegate_declaration [4, 4] - [4, 50]
        (modifier [4, 4] - [4, 11])
        type: (predefined_type [4, 21] - [4, 24])
        name: (identifier [4, 25] - [4, 38])
        parameters: (parameter_list [4, 38] - [4, 49]
          (parameter [4, 39] - [4, 48]
            (parameter_modifier [4, 39] - [4, 42])
            type: (predefined_type [4, 43] - [4, 46])
            name: (identifier [4, 47] - [4, 48]))))
      (method_declaration [6, 4] - [11, 5]
        (modifier [6, 4] - [6, 10])
        (modifier [6, 11] - [6, 17])
        type: (void_keyword [6, 18] - [6, 22])
        name: (identifier [6, 23] - [6, 27])
        parameters: (parameter_list [6, 27] - [6, 29])
        body: (block [7, 4] - [11, 5]
          (local_declaration_statement [8, 8] - [8, 47]
            (variable_declaration [8, 8] - [8, 46]
              type: (identifier [8, 8] - [8, 21])
              (variable_declarator [8, 22] - [8, 46]
                (identifier [8, 22] - [8, 23])
                (equals_value_clause [8, 24] - [8, 46]
                  (lambda_expression [8, 26] - [8, 46]
                    (parameter_list [8, 26] - [8, 37]
                      (ERROR [8, 27] - [8, 36]
                        (argument [8, 27] - [8, 36]
                          (declaration_expression [8, 31] - [8, 36]
                            type: (predefined_type [8, 31] - [8, 34])
                            name: (identifier [8, 35] - [8, 36])))))
                    body: (binary_expression [8, 41] - [8, 46]
                      left: (identifier [8, 41] - [8, 42])
                      right: (integer_literal [8, 45] - [8, 46])))))))
          (local_declaration_statement [9, 8] - [9, 21]
            (variable_declaration [9, 8] - [9, 20]
              type: (implicit_type [9, 8] - [9, 11])
              (variable_declarator [9, 12] - [9, 20]
                (identifier [9, 12] - [9, 16])
                (equals_value_clause [9, 17] - [9, 20]
                  (integer_literal [9, 19] - [9, 20])))))
          (expression_statement [10, 8] - [10, 39]
            (invocation_expression [10, 8] - [10, 38]
              function: (member_access_expression [10, 8] - [10, 25]
                expression: (identifier [10, 8] - [10, 15])
                name: (identifier [10, 16] - [10, 25]))
              arguments: (argument_list [10, 25] - [10, 38]
                (argument [10, 26] - [10, 37]
                  (invocation_expression [10, 26] - [10, 37]
                    function: (identifier [10, 26] - [10, 27])
                    arguments: (argument_list [10, 27] - [10, 37]
                      (argument [10, 28] - [10, 36]
                        (identifier [10, 32] - [10, 36])))))))))))))
Program.cs	0 ms	(ERROR [8, 27] - [8, 36])