Skip to content

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

@aibaars

Description

@aibaars

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 github/codeql#14279

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions