Skip to content

debug.getinfo(level, 'n') returns nil for name and namewhat #279

Closed

Description

@davydog187

Symptom

debug.getinfo(level, "n") returns a table whose name field is always nil (and namewhat is never set), regardless of how the function was called.

Repro

function F(a) return a end
F(1)
assert(debug.getinfo(1, "n").name == 'F')  -- fails: name == nil

This blocks test/lua53_tests/constructs.lua at line 226.

Where it lives

lib/lua/vm/stdlib/debug.ex:54-129. Every code path through debug_getinfo/2 and stack_info_for_level/2 sets "name" => nil unconditionally (lines 64, 76, 87, 101, 118, 126). "namewhat" is never populated.

Why it's non-trivial

Per the Lua 5.3 reference manual, the "n" field is derived by inspecting the caller's call instruction at the call site. PUC-Lua's getfuncname walks the parent frame's bytecode looking for OP_GETGLOBAL, OP_GETUPVAL, OP_GETTABLE, or OP_SELF and recovers a textual name from the constant pool.

lib/lua/compiler/prototype.ex (%Lua.Compiler.Prototype{}) does not retain the metadata needed for that lookup. Implementing this correctly needs either:

  1. Per-function-decl name capture during codegen (only handles the common function X(...) and local function X(...) forms; misses table fields, dynamic dispatch, anonymous closures used positionally), or
  2. Caller-instruction inspection at call time, PUC-Lua style. Heavier — needs the call-stack frame to retain the caller's pc and bytecode reference for after-the-fact decoding.

Suite impact

Surfaces in constructs.lua line 226 (currently skipped via narrowed range, see linked PR). Likely surfaces elsewhere in the suite for any test that uses debug.getinfo("n") for introspection.

Related

Activity

  1. added
    bugSomething isn't working
    direction:ADirection A: suite triage to 0.5.0
    kind:suiteLua 5.3 official test suite work
    on May 28, 2026
  2. added a commit that references this issue on May 31, 2026
    14267b6
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

    bugSomething isn't workingdirection:ADirection A: suite triage to 0.5.0kind:suiteLua 5.3 official test suite work

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions