tree-sitter / tree-sitter-ruby

Ruby grammar for tree-sitter
MIT License
176 stars 58 forks source link

Syntax error in one line `def` with a command call as right-hand side #242

Open aibaars opened 11 months ago

aibaars commented 11 months ago

The following ruby code causes an extraction error when parsed.

def foo() = raise NotImplementedError

The parse tree looks as follows in the tree-sitter playground

program [0, 0] - [1, 0]
  method [0, 0] - [0, 37]
    name: identifier [0, 4] - [0, 7]
    parameters: method_parameters [0, 7] - [0, 9]
    ERROR [0, 12] - [0, 17]
      identifier [0, 12] - [0, 17] <-- raise
    constant [0, 18] - [0, 37]     <-- NotImplementedError

This code is correct ruby syntax.

The problem is the command call on the right-hand side, things parse correctly with a parenthesized argument list.

def foo() = raise(NotImplementedError)
program [0, 0] - [1, 0]
  method [0, 0] - [0, 38]
    name: identifier [0, 4] - [0, 7]
    parameters: method_parameters [0, 7] - [0, 9]
    call [0, 12] - [0, 38]
      method: identifier [0, 12] - [0, 17]
      arguments: argument_list [0, 17] - [0, 38]
        constant [0, 18] - [0, 37]

This problem was reproduced with CodeQL version 2.4.5.

Originally reported at https://github.com/github/codeql/issues/14279