slackhq / tree-sitter-hack

Hack grammar for tree-sitter
MIT License
33 stars 16 forks source link

[BUG] Typed collection initializers are not parsed correctly #57

Closed andryak closed 7 months ago

andryak commented 1 year ago

Describe the bug

The parser does not recognise typed collection initializers.

This is valid Hack code to generate a vector of strings:

$x = Vector<string> {'foo', 'bar'};

Yet, the parser does not recognize the syntax and mistakes it for a function pointer:

(expression_statement
        (function_pointer
          (qualified_identifier
            (identifier))
          (type_arguments
            (type_specifier)))
        (MISSING ";"))
      (compound_statement
        (ERROR
          (string)
          (string)))
      (empty_statement))

Requirements

To Reproduce

Add Set<string> {'foo', 'bar'}; to the Collection test in test/corpus/expressions.txt, then run tree-sitter test.

Expected behavior

No errors are reported in the syntax tree.

Additional context

Issue is more general that Set<type arguments> { ... }, applies to Map(s) and Vector(s) as well, possibly to more types.