Skip to content

Invalid Node Type Error with returns in Query #358

Open
@VishwasSomasekhariah

Description

@VishwasSomasekhariah

Invalid Node Type Error with returns in Query

Issue Description

I am encountering an issue when querying method_declaration nodes using Tree-sitter. Specifically, using the field returns in my query causes an Invalid Node Type error, while replacing it with type resolves the issue.

Query Example Causing the Error

(class_declaration
  name: (identifier)
  body: (declaration_list
    (method_declaration
      (modifier)
      returns: (predefined_type)
      name: (identifier)
      parameters: (parameter_list
        (parameter
          type: (predefined_type)
          name: (identifier)))
      body: (block
        (return_statement
          (identifier))))))

Expected Behavior

The query should retrieve all method_declaration nodes with their attributes, including the returns field for the return type.

File Context

I am using the example provided in the test/corpus/type-methods.txt with the following structure:

(compilation_unit
  (class_declaration
    name: (identifier)
    body: (declaration_list
      (method_declaration
        (modifier)
        returns: (predefined_type)
        name: (identifier)
        parameters: (parameter_list
          (parameter
            type: (predefined_type)
            name: (identifier)))))

Problem

The grammar for method_declaration nodes in the provided file references returns for the return type of the method. However, when querying with returns, Tree-sitter raises an error about an invalid node type. Replacing it with type works, but it seems inconsistent with the provided grammar definition.

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