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

Conversation

@bm-w
Copy link

@bm-w bm-w commented Apr 2, 2025

A lambda without parameters does not have a syntax for the parameters, unlike a function without parameters (which does, containing just the ( and ) characters). The stanza for callables did not optionally match @params, causing it to miss lambdas without parameters entirely, which would then cause an error in a later stanza:

0: Error executing statement edge @lam.output -> @lam.call at (984, 3)
    src/stack-graphs.tsg:984:3:
    984 |   edge @lam.output -> @lam.call
        |   ^
    in stanza
    src/stack-graphs.tsg:975:1:
    975 | (lambda
        | ^
    matching (lambda) node
    test/lambdas.py:6:7:
    6 | foo = lambda: print(y)
        |       ^
1: Evaluating edge sink
2: Undefined scoped variable [syntax node lambda (6, 7)].call

The fragments of the parsed Tree-sitter tree for such lambda without and with parameters is:

(lambda [6, 7] - [6, 23])
  body: …)
(lambda [9, 7] - [9, 32])
  parameters: (lambda parameters …)
  body: …)

As of v0.23.5 of the Python grammar, lambda indeed declares an optional parameters field.

Making the @params capture optional and only emitting the edges if it’s there fixes the issue.

Copilot AI review requested due to automatic review settings April 2, 2025 00:30
@bm-w bm-w requested review from a team as code owners April 2, 2025 00:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue with lambdas without parameters by making the capture of @params optional, ensuring that call edges are only emitted if parameters are present.

  • Added a test case for lambdas without parameters.
  • Verified lambdas with parameters continue to work as expected.
Files not reviewed (1)
  • languages/tree-sitter-stack-graphs-python/src/stack-graphs.tsg: Language not supported

@CleanCut
Copy link
Contributor

CleanCut commented Sep 9, 2025

The github/stack-graphs repository is no longer being maintained. As per #502, I'm closing all issues and pull requests before archiving the repository.

@CleanCut CleanCut closed this Sep 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants