Skip to content

compiler: _ENV upvalue is handed to every nested function (PUC only when free names are read) #412

Description

@davydog187

Found during automated review of PR #400 (pre-existing divergence, also noted in that PR's description).

For local a, b = 1, 2; local function f() return a + b + a end, debug.getupvalue enumeration gives _ENV, a, b (nups == 3); PUC-Lua 5.3 gives a, b (nups == 2) because _ENV is only added to functions that actually reference a free (global) name.

Observable via debug.getupvalue/debug.upvalueid and upvalue counts; also a small perf cost (every closure carries an extra descriptor/cell hop).

Note: test/lua/compiler/upvalue_descriptor_test.exs pins the current (divergent) "_ENV,a,b" output — when fixing this, that expectation flips and is not a regression.

🤖 Filed from an automated review pass.

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