Skip to content

local function declarations are silently dropped #144

Closed

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

Activity

  1. davydog187 commented on May 4, 2026

    @davydog187
    ContributorAuthor

    This was fixed in #137 (Phase 11 — Compiler Fundamentals).

    Verified on main (835de36):

    local function add(a, b) return a + b end
    return add(1, 2)  -- returns 3 ✓

    Closing as resolved. Future regressions are tracked via the suite-status CI job and the .agents/plans/ workflow.

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 working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions