From c764ca71a639f5585b5f466bea25dc42b855a4b0 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 25 Apr 2022 14:42:51 -0300 Subject: Bug: Wrong code generation in bitwise operations --- testes/constructs.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'testes') diff --git a/testes/constructs.lua b/testes/constructs.lua index a74a8c04..0d9ec92d 100644 --- a/testes/constructs.lua +++ b/testes/constructs.lua @@ -103,6 +103,31 @@ do -- test old bug (first name could not be an `upvalue') local a; function f(x) x={a=1}; x={x=1}; x={G=1} end end + +do -- bug since 5.4.0 + -- create code with a table using more than 256 constants + local code = {"local x = {"} + for i = 1, 257 do + code[#code + 1] = i .. ".1," + end + code[#code + 1] = "};" + code = table.concat(code) + + -- add "ret" to the end of that code and checks that + -- it produces the expected value "val" + local function check (ret, val) + local code = code .. ret + code = load(code) + assert(code() == val) + end + + check("return (1 ~ (2 or 3))", 1 ~ 2) + check("return (1 | (2 or 3))", 1 | 2) + check("return (1 + (2 or 3))", 1 + 2) + check("return (1 << (2 or 3))", 1 << 2) +end + + function f (i) if type(i) ~= 'number' then return i,'jojo'; end; if i > 0 then return i, f(i-1); end; -- cgit v1.2.3-55-g6feb