tree-sitter / tree-sitter-python

Python grammar for tree-sitter
MIT License
372 stars 138 forks source link

bug: arguments in Callable not marked as types #258

Closed MithicSpirit closed 8 months ago

MithicSpirit commented 8 months ago

Did you check existing issues?

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

No response

Describe the bug

The arguments in a Callable are highlighted as variables/constants rather than as types.

Steps To Reproduce/Bad Parse Tree

See repro

Expected Behavior/Parse Tree

The t should be a @type, but it is a @variable instead. If it is changed to T, then it is both a @variable and a @constant. Note that the u is correctly identified as an @type, and further testing suggests that the issue is the double brackets [[.

Repro

f: Callable[[t], u]
amaanq commented 8 months ago

this repo is for the parser, so issues should be parse issues, any query/highlighting issues should be filed with the provider of that.

MithicSpirit commented 8 months ago

Sorry, I misunderstood the scope of this project. Either way, I still believe that the issue is present in this project. The tree (see below) shows that the [t] is interpreted as a type that is a list, while the t itself is just an identifier, when it should also be a type (like u).

(module [0, 0] - [1, 0]
  (expression_statement [0, 0] - [0, 19]
    (assignment [0, 0] - [0, 19]
      left: (identifier [0, 0] - [0, 1])
      type: (type [0, 3] - [0, 19]
        (generic_type [0, 3] - [0, 19]
          (identifier [0, 3] - [0, 11])
          (type_parameter [0, 11] - [0, 19]
            (type [0, 12] - [0, 15]
              (list [0, 12] - [0, 15]
                (identifier [0, 13] - [0, 14])))
            (type [0, 17] - [0, 18]
              (identifier [0, 17] - [0, 18]))))))))
amaanq commented 8 months ago

that's intentional, tree-sitter does not provide semantic info, the type rule is a wrapper (supertype) around what rules are allowed in this construct, it could be an identifier, a list, etc.