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

wrong parsing of return statement #17

Open
mindtraveller opened this issue Jun 9, 2021 · 2 comments
Open

wrong parsing of return statement #17

mindtraveller opened this issue Jun 9, 2021 · 2 comments

Comments

@mindtraveller
Copy link

the following code

class Class {

    fun method() {
        return listOf(
            A(),
            B()
        )
    }

}

during parsing becomes

    (source_file 
          (class_declaration (type_identifier) 
             (class_body 
               (function_declaration (simple_identifier) 
                 (function_body 
                   (statements 
                     (infix_expression (jump_expression) (simple_identifier) 
                      (parenthesized_expression (call_expression 
                        (call_expression (simple_identifier) (call_suffix (value_arguments))) 
                        (ERROR (UNEXPECTED 'B')(call_suffix (value_arguments))
)))))))))

Similar list initialization e.g. for a local variable works fine.

@matheusalcantarazup
Copy link

matheusalcantarazup commented Jul 27, 2021

I think that the problem here is that the parser think that a return statement with a call_expression is a infix_expression, but a infix expression can not have more than 1 parameter.

If we parse the following code

class Class {

    fun method() {
        return listOf(
            A()
        )
    }

}

The S-expression will become

(
 source_file (
     class_declaration (type_identifier) (
         class_body (
             function_declaration (simple_identifier) (
                 function_body (
                     statements (
                         infix_expression (jump_expression) (simple_identifier) (
                             parenthesized_expression (call_expression (simple_identifier) (call_suffix (value_arguments)))
                             )
                         )
                     )
                 )
             )
         )
     )
 )

@ObserverOfTime
Copy link
Contributor

ObserverOfTime commented Oct 16, 2023

This has been fixed.

(source_file [0, 0] - [10, 0]
  (class_declaration [0, 0] - [9, 1]
    (type_identifier [0, 6] - [0, 11])
    (class_body [0, 12] - [9, 1]
      (function_declaration [2, 4] - [7, 5]
        (simple_identifier [2, 8] - [2, 14])
        (function_value_parameters [2, 14] - [2, 16])
        (function_body [2, 17] - [7, 5]
          (statements [3, 8] - [6, 9]
            (jump_expression [3, 8] - [6, 9]
              (call_expression [3, 15] - [6, 9]
                (simple_identifier [3, 15] - [3, 21])
                (call_suffix [3, 21] - [6, 9]
                  (value_arguments [3, 21] - [6, 9]
                    (value_argument [4, 12] - [4, 15]
                      (call_expression [4, 12] - [4, 15]
                        (simple_identifier [4, 12] - [4, 13])
                        (call_suffix [4, 13] - [4, 15]
                          (value_arguments [4, 13] - [4, 15]))))
                    (value_argument [5, 12] - [5, 15]
                      (call_expression [5, 12] - [5, 15]
                        (simple_identifier [5, 12] - [5, 13])
                        (call_suffix [5, 13] - [5, 15]
                          (value_arguments [5, 13] - [5, 15]))))))))))))))

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

No branches or pull requests

3 participants