Skip to content

function Table.method() dot-syntax declarations fail at runtime #145

Closed

Description

@davydog187

Severity: High
Area: Compiler — codegen.ex / scope resolver

Description

Declaring a method with dot-syntax — function Animal.new(...) — creates a new Expr.Var{name: "Animal", meta: nil} node during codegen. This node never matches any entry in var_map (whose keys are original AST nodes with non-nil meta), so the lookup returns nil, causing a runtime crash.

Reproduction

Animal = {}
function Animal.new(name)
  return {name = name}
end
return Animal.new("Cat")
-- Expected: table {name="Cat"}
-- Actual: ** (MatchError) no match of right hand side value: nil

Workaround

Use assignment-style method declarations:

Animal = {}
Animal.new = function(name)
  return {name = name}
end

Activity

  1. davydog187 commented on May 4, 2026

    @davydog187
    ContributorAuthor

    This was fixed in PR #141 (Phase 17 — Vararg expansion, scope fixes, and suite triage).

    Verified on main (835de36):

    local t = {}
    function t.method() return "ok" end
    return t.method()  -- returns "ok" ✓

    Closing as resolved.

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