tree-sitter / tree-sitter-scala

Scala grammar for tree-sitter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect AST when parsing assignment within a lambda expression

ghostbuster91 opened this issue · comments

Commit of tree-sitter-scala you tested this on

1b4c2fa

A code sample showing the error

val a: String => String = { input =>
  val kind = "arst"
  kind
}

image

Show the error node

        val_definition [84, 4] - [87, 5]
          pattern: identifier [84, 8] - [84, 9]
          type: function_type [84, 11] - [84, 27]
            parameter_types: parameter_types [84, 11] - [84, 17]
              type_identifier [84, 11] - [84, 17]
            return_type: type_identifier [84, 21] - [84, 27]
          value: block [84, 30] - [87, 5]
            lambda_expression [84, 32] - [85, 16]
              parameters: identifier [84, 32] - [84, 37]
              infix_expression [85, 6] - [85, 16]
                left: identifier [85, 6] - [85, 9]
                operator: identifier [85, 10] - [85, 14]
                right: operator_identifier [85, 15] - [85, 16]
            ERROR [85, 17] - [85, 23]
            identifier [86, 6] - [86, 10]

image

What do you expect the tree to look like

I would expect it to be parsed correctly as val_definition

Where are you experiencing this error?

nvim-treesitter

@ghostbuster91
I'm unable to reproduce this on 696965e, parse result is

(compilation_unit [0, 0] - [4, 0]
  (val_definition [0, 0] - [3, 1]
    pattern: (identifier [0, 4] - [0, 5])
    type: (function_type [0, 7] - [0, 23]
      parameter_types: (parameter_types [0, 7] - [0, 13]
        (type_identifier [0, 7] - [0, 13]))
      return_type: (type_identifier [0, 17] - [0, 23]))
    value: (block [0, 26] - [3, 1]
      (lambda_expression [0, 28] - [3, 0]
        parameters: (identifier [0, 28] - [0, 33])
        (indented_block [1, 2] - [3, 0]
          (val_definition [1, 2] - [1, 19]
            pattern: (identifier [1, 6] - [1, 10])
            value: (string [1, 13] - [1, 19]))
          (identifier [2, 2] - [2, 6]))))))

Could you please check if erroneous behaviour remains?

Strange, I am no longer able to reproduce this issue on the original commit hash. Seems like this was an issue with some stale parts of treesitter on my machine. All good then and sorry for the trouble.