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