UserNobody14 / tree-sitter-dart

Attempt to make a tree-sitter grammar for dart
MIT License
56 stars 33 forks source link

Infinite loop when parsing a incomplete assignment expression with type argument #40

Closed Syndim closed 1 year ago

Syndim commented 1 year ago

The minimal code snippet that can reproduce this bug is:

final a = StateProvider<T1234567>   // Complete expression is: final a = StateProvider<T1234567>();

Running tree-sitter parse <path/to/above/example.dart> will cause an infinite loop. Strangely if the length of argument type name is less than 7(i.e. StateProvider<T123456>), this issue doesn't happen.

I tried to play around the grammar.js to locate the issue, and it looks it's related this rule in postfix_expression:

        _postfix_expression: $ => choice(
          // Commenting out the rule below will resolve this issue            
          seq(
                $._primary,
                repeat(
                    $.selector
                )
            ),
            $.postfix_expression
        ),

Any idea why this expression matches the postfix expression and causes the infinite loop? Thanks!

SilverMira commented 1 year ago

Probably facing same issue while using this parser within Neovim, some nvim-cmp suggestions straight up freezes neovim, and pins one of my cores to 100%

TimWhiting commented 1 year ago

Fixed in latest commit