Skip to content

Lua: function reassigned to global builtin (require = traced_require) flagged as false-positive dead-unresolved #1776

Description

@carlos-alm

Description

`codegraph roles --role dead -T --file tests/benchmarks/resolution/tracer/lua-tracer.lua --json` flags `traced_require` (line 41-52) as `kind=function, role=dead-unresolved` (totalDependents: 0, direct: 0, transitive: 0 per `fn-impact`), despite it being genuinely invoked at runtime.

Root cause

The function is not called by its own name — it's assigned to the global `require` builtin via a monkey-patch:

```lua
local orig_require = require
local function traced_require(modname)
...
end
require = traced_require


Every subsequent `require(...)` call anywhere in the fixture (including in other files loaded via `dofile`) actually invokes `traced_require`, but codegraph's static resolver has no way to trace a call through a reassigned global builtin identifier — it only sees `require = traced_require` (an assignment, not a call) and no direct `traced_require(...)` call sites anywhere in the codebase.

## Why this matters

This is a distinct root cause from the already-filed #1723 (interface members / used parameters mis-flagged dead) and #1771 (dispatch-table fanOut inconsistency) — it's a genuine "function assigned to a builtin/global and invoked indirectly through that identifier" pattern that the dead-code classifier has no signal for.

## Repro

\`\`\`bash
codegraph roles --role dead -T --file tests/benchmarks/resolution/tracer/lua-tracer.lua --json
codegraph fn-impact traced_require -T --json   # totalDependents: 0
\`\`\`

## Context

Found during Titan grind phase 29 processing (forge commit 8386f711, which only touched the pcall error-logging block in this file — \`traced_require\` itself predates that commit and was not created/modified by it). Classified false-positive; no code change made since the function is provably live via the \`require = traced_require\` reassignment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions