tree-sitter / tree-sitter-ruby

Ruby grammar for tree-sitter
MIT License
186 stars 55 forks source link

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

Open aibaars opened 1 year ago

aibaars commented 1 year 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

mitio commented 1 month ago

Hey folks, has anyone been able to look into this? Appreciate any update on the matter.