Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple return values not parsed correctly #107

Closed
edkolev opened this issue Feb 6, 2023 · 1 comment · Fixed by #118
Closed

Multiple return values not parsed correctly #107

edkolev opened this issue Feb 6, 2023 · 1 comment · Fixed by #118

Comments

@edkolev
Copy link

edkolev commented Feb 6, 2023

I've run into the following issue: multiples return values of functions are not always parsed correctly.

For example:

  • the return values of func notOk() (int, map[int]int) are parsed incorrectly into
(parameter_list (
  (parameter_declaration ... 
     (array_type ...))    // incorrect - should have two parameter_declaration instead of one,
                          // no array_type expected, map_type expected

To reproduce:

  • with Go code
func ok() ([]int, map[int]int) {
    return nil, nil
}

func notOk() (int, map[int]int) {
    return 0, nil
}
  • inspect the tree, I use M-x treesit-explore-mode in emacs. The whole tree is pasted below. EDIT: below in a comment is the tree produced by tree-sitter parse ....

  • the first function "ok" is as expected - ([]int, map[int]int) is parsed into one parameter_list with two parameter_declaration branches:

result:
   (parameter_list (
    (parameter_declaration
     type: (slice_type [ ] element: (type_identifier)))
    ,
    (parameter_declaration
     type: (map_type map [ key: (type_identifier) ] value: (type_identifier)))
))
  • the second function "notOk" is not parsed as expected - (int, map[int]int) is parsed into one parameter_list with one parameter_declaration branches, I expect two parameter_declaration branches.
  result:
   (parameter_list (
    (parameter_declaration name: (identifier) name: , type: (identifier)
     (array_type [ length: (identifier) ] element: (type_identifier)))
    ))

Full tree:

(source_file
 (package_clause package (package_identifier))
 \n (comment)
 (function_declaration func name: (identifier)
  parameters: (parameter_list ( ))
  result:
   (parameter_list (
    (parameter_declaration
     type: (slice_type [ ] element: (type_identifier)))
    ,
    (parameter_declaration
     type: (map_type map [ key: (type_identifier) ] value: (type_identifier)))
    ))
  body:
   (block {
    (return_statement return
     (expression_list (nil) , (nil)))
    \n }))
 \n
 (function_declaration func name: (identifier)
  parameters: (parameter_list ( ))
  result:
   (parameter_list (
    (parameter_declaration name: (identifier) name: , type: (identifier)
     (array_type [ length: (identifier) ] element: (type_identifier)))
    ))
  body:
   (block {
    (return_statement return
     (expression_list (int_literal) , (nil)))
    \n }))
 \n)
@edkolev
Copy link
Author

edkolev commented Feb 7, 2023

Here's a minimalistic example:

  1. with input
func notOk() (int, map[int]int) {}
  1. output by tree-sitter parse ...
(source_file [0, 0] - [1, 0]
  (function_declaration [0, 0] - [0, 34]
    name: (identifier [0, 5] - [0, 10])
    parameters: (parameter_list [0, 10] - [0, 12])
    result: (parameter_list [0, 13] - [0, 31]
      (parameter_declaration [0, 14] - [0, 30]
        name: (identifier [0, 14] - [0, 17])
        name: (identifier [0, 19] - [0, 22])
        type: (array_type [0, 22] - [0, 30]
          length: (identifier [0, 23] - [0, 26])
          element: (type_identifier [0, 27] - [0, 30]))))
    body: (block [0, 32] - [0, 34])))
  1. you can see the "bad" array_type in the output

Attached is a screenshot of log.html

Screenshot 2023-02-07 at 7 05 35

This was referenced May 22, 2023
@aryx aryx closed this as completed in #118 May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant