Skip to content

local function declarations are silently dropped #144

@davydog187

Description

@davydog187

Severity: High
Area: Compiler — codegen.ex

Description

local function name() ... end (i.e., Statement.LocalFunc AST nodes) has no codegen handler. The catch-all defp gen_statement(_stmt, ctx), do: {[], ctx} silently discards the declaration — no instructions are emitted and no error is raised.

Reproduction

local function add(a, b)
  return a + b
end
return add(1, 2)
-- Expected: 3
-- Actual: runtime error — "add" is nil

Workaround

Use a regular (global) function declaration or an assignment:

function add(a, b)   -- global
  return a + b
end

local add = function(a, b)   -- explicit assignment
  return a + b
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions