Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Python TSG: Chained assignment fails to be recognised  #402

@SubhamPramanik

Description

@SubhamPramanik

Python code:

repeat_hi = repeat_lo = repeat_avg = None

The following Stanza fails:

[
  (assignment
    left: (_) @pattern
    right: (_) @value)
  (with_item
    value:
      (as_pattern
        (_) @value
        alias: (as_pattern_target (_) @pattern)))
]
{
  edge @pattern.input -> @value.output
}

Error thrown:

    0: Error executing statement edge @pattern.input -> @value.output at (1268, 3)
       src/stack-graphs.tsg:1268:3:
       1269 |   edge @pattern.input -> @value.output
            |   ^
       in stanza
       src/stack-graphs.tsg:1258:1:
       1258 | [
            | ^
       matching (assignment) node
       benchmark.py:121:9:
       121 |         repeat_hi = repeat_lo = repeat_avg = None 
           |         ^
    1: Evaluating edge sink
    2: Undefined scoped variable [syntax node assignment (121, 21)].output

I believe that the TS query is not able to work with chained assignments since the first occurrence of right is incorrect.

[expression_statement](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [0, 41]
    [assignment](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [0, 41]
      left: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [0, 9]
      right: [assignment](https://tree-sitter.github.io/tree-sitter/playground#) [0, 12] - [0, 41]
        left: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 12] - [0, 21]
        right: [assignment](https://tree-sitter.github.io/tree-sitter/playground#) [0, 24] - [0, 41]
          left: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 24] - [0, 34]
          right: [none](https://tree-sitter.github.io/tree-sitter/playground#) [0, 37] - [0, 41]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions