Vararg expression (...) inconsistent behaviour
Brought to you by:
ian_farmer,
jim_roseborough
Got some weird behaviour of multiple variable assignment using identity function:
local I = function(...) return ... end
So
local v1, v2, v3 = I(val1, val2, val3)
become
v1 == val3
v2 == val3
v3 == val3
instead of
v1 == val1
v2 == val2
v3 == val3
In plain 5.2 lua:
> lua
Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio
> local i = function(...) return ... end print(i(1, 2, 3)) local v1, v2, v3 = i(1, 2, 3) print(v1, v2, v3)
1 2 3
1 2 3
In luaj:
> java -cp lib/luaj-jse-3.0.jar lua -v
Luaj-jse 3.0 Copyright (c) 2012 Luaj.org.org
> java -cp lib/luaj-jse-3.0.jar lua
> local i = function(...) return ... end print(i(1, 2, 3)) local v1, v2, v3 = i(1, 2, 3) print(v1, v2, v3)
1 2 3
3 3 3
But it unexpectedly works as intended with 2 variables
java -cp lib/luaj-jse-3.0.jar lua -v
Luaj-jse 3.0 Copyright (c) 2012 Luaj.org.org
> java -cp lib/luaj-jse-3.0.jar lua
> local i = function(...) return ... end print(i(1, 2)) local v1, v2 = i(1, 2) print(v1, v2)
1 2
1 2
This was happening for some but not all cases of varargs return values being assigned using a multiple assignment statement.
A unit test has been added to reproduce this and a fix has been applied for v 3.0.1
Is fixed in version 3.0.1.