Skip to content

Commit 81b2cc7

Browse files
authored
tests: Adjust conformance tests to account for array invariant (#1289)
These were written before compiler optimizations and array invariant. It is now impossible for t[1] to be stored in the hash part, as this would violate the array invariant that says that elements 1..#t are stored in the array. For ipairs, it doesn't traverse the hash part anymore now, so we adjust the code to make sure no elements outside of the 1..#t slice are covered. For table.find, we can use find-with-offset to still access the hash part. Fixes #1283.
1 parent 23b8726 commit 81b2cc7

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

tests/conformance/basic.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,16 +726,15 @@ assert((function()
726726
return sum
727727
end)() == 15)
728728

729-
-- the reason why this test is interesting is that the table created here has arraysize=0 and a single hash element with key = 1.0
730-
-- ipairs must iterate through that
729+
-- ipairs will not iterate through hash part
731730
assert((function()
732-
local arr = { [1] = 42 }
731+
local arr = { [1] = 1, [42] = 42, x = 10 }
733732
local sum = 0
734733
for i,v in ipairs(arr) do
735734
sum = sum + v
736735
end
737736
return sum
738-
end)() == 42)
737+
end)() == 1)
739738

740739
-- the reason why this test is interesting is it ensures we do correct mutability analysis for locals
741740
local function chainTest(n)

tests/conformance/tables.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,8 @@ do
412412

413413
assert(table.find({false, true}, true) == 2)
414414

415-
-- make sure table.find checks the hash portion as well by constructing a table literal that forces the value into the hash part
416-
assert(table.find({[(1)] = true}, true) == 1)
415+
-- make sure table.find checks the hash portion as well
416+
assert(table.find({[(2)] = true}, true, 2) == 2)
417417
end
418418

419419
-- test table.concat

0 commit comments

Comments
 (0)