Skip to content

Query with supertype fails when it shouldn't #245

Closed
@yuriv

Description

@yuriv

Problem

The results of the generic and detailed query on function_definition non-terminal are not same. This only happens on specified non-terminal.

Query (function_definition declarator: (_declarator) @f.decl) @f.def works fine on void foo(void) {} snippet, but doesn't work on void foo() {}.

Steps to reproduce

Clone tree-sitter-c repository

Build tree-sitter-c.wasm module

Run playground

Put void foo() {} to source widget
You will see in tree widget
[translation_unit](http://127.0.0.1:8001/#) [0, 0] - [2, 0]
[function_definition](http://127.0.0.1:8001/#) [0, 0] - [0, 13]
type: [primitive_type](http://127.0.0.1:8001/#) [0, 0] - [0, 4]
declarator: [function_declarator](http://127.0.0.1:8001/#) [0, 5] - [0, 10]
declarator: [identifier](http://127.0.0.1:8001/#) [0, 5] - [0, 8]
parameters: [parameter_list](http://127.0.0.1:8001/#) [0, 8] - [0, 10]
body: [compound_statement](http://127.0.0.1:8001/#) [0, 11] - [0, 13]

Put generic query (function_definition) @f.def to query widget
You will see properly highlighted source

Comment generic query

Put detailed query (function_definition declarator: (_declarator) @f.decl) @f.def to query widget
You will see no highlighting

Expected behavior

In both cases you should see respectively highlighted source. I have checked it by API calling the result is same. If you will add parameter to the function foo all done properly.

Tree-sitter version (tree-sitter --version)

tree-sitter 0.22.6

Operating system/version

Rocky Linux 8.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions