Skip to content

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

@davydog187

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

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