Skip to content

JS: a variable captured from an enclosing function is not shadowed, so passing it as an argument fabricates an indirect_call to any same-named function in the corpus #5217

Closed

Description

@laurism-openelms

Version: 0.9.109 (macOS, graphify extract . --code-only)

Related: #4448 (fixed in 0.9.91 for parameters of the callback itself). This is the remaining case.

Summary

When an identifier is a parameter of an enclosing function and is used as a call argument inside a nested function, the inner reference is treated as a free name and resolved corpus-wide. It binds to any function with the same name, even a non-exported function in a TypeScript file that nothing imports. A parameter used directly in its own function is shadowed correctly.

Reproduction

app/controller.js:

angular.module('app').controller('ListCtrl', function ($scope, $ngConfirm) {
  // A: param of the immediate nested function
  $scope.a = function (value) {
    save(value);
  };
  // B: variable captured from an enclosing nested function
  $scope.remove = function (item) {
    $ngConfirm({
      buttons: { confirm: { action: function () { doDelete(item); } } }
    });
  };
  // C: arrow param captured one level down
  $scope.load = function (rows) {
    rows.forEach((entry) => {
      if (entry) { setTimeout(function () { show(entry); }); }
    });
  };
});

web/helpers.ts (not exported, not imported anywhere):

async function value(r: Response): Promise<unknown> { return r.json(); }
function item(): number { return 2; }
function entry(): number { return 3; }

Run graphify extract . --code-only, then list edges whose target is in web/.

Expected

Only the three contains edges from helpers.ts. item and entry in the controller are local variables.

Actual

('indirect_call', 'INFERRED', 'controller.js', 'item()',  'L9')
('indirect_call', 'INFERRED', 'controller.js', 'entry()', 'L15')

Case A (value) gives no edge, so the direct-parameter shadowing from #4448 works. Cases B and C do not: the reference sits in an inner function whose own scope does not declare the name, and the lookup does not walk out to the enclosing function's parameters before it falls back to the corpus.

Impact

In a real codebase that mixes an AngularJS frontend with a separate TypeScript app, this leaves 55 INFERRED indirect_call edges between two layers that never call each other. All of them go to functions with generic names such as scope(), entry(), value(), response() and item(). The edges also pull unrelated files into the same communities.

Suggested direction

When resolving a bare identifier used as a call argument, check the chain of enclosing function scopes (parameters and local declarations), not only the innermost one, before the corpus-wide fallback. A resolution that crosses into a non-exported symbol of a file that the caller does not import could also fail closed.

Activity

  1. github-actions commented on Nov 15, 2026

    @github-actions

    Thanks for opening this issue, @laurism-openelms. 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.

  2. safishamsi commented on Nov 15, 2026

    @safishamsi
    Member

    Fixed by #5221 (ccb43e9), released in graphify 0.9.110. Thanks @laurism-openelms for the report and @Sidreyas for the fix.

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