Skip to content

Bash extractor: a nested function's defines edge comes from the outer function, so the outer's call to it is lost #5573

Backlog

Description

@yashsaxena

What happens

A function defined inside another function's body, called from there, loses that call:

outer() {
  inner() { echo hello; }
  inner
}

The extractor gives inner a defines edge from outer, and outer a calls edge to inner.
The graph keeps one edge per pair of nodes, so the defines takes the pair and the calls is gone.
In bash, inner is a function of the file once outer runs, not a part of outer.

Reproduced on graphifyy 0.9.122 (newest on PyPI), installed with pip, nothing patched, Python 3.12, Ubuntu.

Reproduction

Two files in a new git repo:

# bin/tool
#!/usr/bin/env bash
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
. "$ROOT/lib/outer.sh"
outer
# lib/outer.sh
outer() {
  inner() { echo hello; }
  inner
}

Command:

graphify extract "$PWD" --code-only --out /tmp/out
jq -r '.links[] | select(.relation != "contains")
       | "\(.relation) \(.source) -> \(.target)"' /tmp/out/graphify-out/graph.json

Expected

defines lib/outer.sh -> lib/outer.sh inner
calls lib/outer.sh outer -> lib/outer.sh inner
calls bin/tool (script) -> lib/outer.sh outer

Got

calls bin/tool (script) -> lib/outer.sh outer
defines lib/outer.sh outer -> lib/outer.sh inner
defines lib/outer.sh -> lib/outer.sh outer
imports_from bin/tool -> lib/outer.sh

Cause and fix

walk() adds the defines edge from parent_nid, which is the outer function inside its body.
Adding it from the file node, as for a top-level function, keeps both edges.
The existing nested-call test (test_extract_bash_nested_function_calls_recorded) is unaffected.
We carry this fix as a local patch and will open a PR.

Activity

  1. github-actions commented on Nov 28, 2026

    @github-actions

    Thanks for opening this issue, @yashsaxena. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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