Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect passing of unassigned arguments #9

Open
haesemaths opened this issue Jan 17, 2012 · 3 comments
Open

Incorrect passing of unassigned arguments #9

haesemaths opened this issue Jan 17, 2012 · 3 comments

Comments

@haesemaths
Copy link

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"
@krka
Copy link
Owner

krka commented Jan 17, 2012

I tried the sample code, but I could not reproduce the errors.

@haesemaths
Copy link
Author

Sorry, when I was testing them I was internally using a return statement I forgot to include in the code.

Try:

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

return f({setmetatable({},{})},0,1)

@krka
Copy link
Owner

krka commented Jan 19, 2012

Thanks, that reproduces it. I'll see if I can get to the bottom of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants