Bug: function bodies are not nested under the function node #17
Clément DELALANDE opened 2 days ago

Summary

func name(...) -> Type: <body> parses the body as a sibling top-level statement, not as a child of function. Verified on examples/Plain.gate:

(source_file [0, 0] - [4, 0]
  ...
  (definition [3, 0] - [3, 22]
    (function [3, 0] - [3, 22]
      name: (word [3, 5] - [3, 12])
      parameters: (function_parameters [3, 12] - [3, 14])
      (arrow [3, 15] - [3, 17])
      (type [3, 18] - [3, 21]
        (primitive_types [3, 18] - [3, 21]))))
  (statement [3, 23] - [3, 39]
    (return [3, 23] - [3, 39] ...)))

The return node is a sibling of function, outside its span. The function rule stops at ::

function: ($) =>
  seq(
    "func",
    field("name", $.word),
    field("parameters", $.function_parameters),
    optional(seq($.arrow, $.type)),
    ":",
  ),

Impact

  • Scoping is wrong (variables declared inside a function are not scoped to it).
  • Any transpiler/LSP that walks function children will see an empty body.
  • tree-sitter query for locals will not associate definitions with their scope.

Expected

function should own a function_block containing statements (assignments, expressions, control flow, nested returns). Body delimiters need to be defined — Gate appears to use : indentation blocks (GDScript style), so a newline+indent terminator is likely needed.

Files

  • grammar.js — function rule
1/1
Type
Bug
Priority
Major
Assignees
Not assigned
Issue Votes (0)
Watchers (1)
Reference
gate/tree-sitter-gate#17
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover