Skip to content

Incorrect passing of unassigned arguments #9

@haesemaths

Description

@haesemaths

In certain situations instead of passing a nil value to an unassigned argument, Kahlua may pass a different value.

The simplest case I can produce is

function f(a,b,c,d)
  print(a,b,c,d)
end

f({setmetatable({},{})},0,1)
-- Prints result "table ..., 0, 1, 1" instead of "table ..., 0, 1, nil"

Whether this error occurs depends on the number of arguments passed to and the position of a setmetatable within another table. Some examples

function g(a,b,c,d,e,f)
  print(a,b,c,d,e,f)
end

g({setmetatable({},{})},0,'x')
-- Correct: "table, 0, 'x', nil, nil, nil "
g({setmetatable({},{})},0,0,'x')
-- Incorrect: "table, 0, 0, 'x', 'x', nil"
g({setmetatable({},{})},0,0,0,'x')
-- Incorrect: "table, 0, 0, 0, 'x', 'x' "
g({0, setmetatable({},{})},0,'x')
-- Correct: "table, 0, 'x', nil, nil, nil "
g({0, setmetatable({},{})},0,0,'x')
-- Correct: "table, 0, 0, 'x', nil, nil"
g({0, setmetatable({},{})},0,0,0,'x')
-- Incorrect: "table, 0, 0, 0, 'x', 'x' "
g({setmetatable({},{}),0},0,0,0,'x')
-- Correct: "table, 0, 0, 0, 'x', 'nil' "

g({setmetatable({},{})},0,0,'x',nil)
-- Correct: "table, 0, 0, 'x', nil, nil"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions