luau-lang / luau

A fast, small, safe, gradually typed embeddable scripting language derived from Lua
https://luau.org
MIT License
3.98k stars 373 forks source link

Test doesn't do what it says it does #1283

Closed dubiousjim closed 3 months ago

dubiousjim commented 4 months ago

These lines say:

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

The test passes, but does it really succeed in testing what it claims to? I added a C function to ltablib.cpp that will just return the arraysize of a table argument. When I then call table.size({[(1)] = true}), I get a return value of 1, indicating that the literal being created puts the entry in the array part, not in the hash part.

Perhaps in some older version of Luau, the table literal was handled in the way this test references, but this behavior is now gone, and the test was never updated?

dubiousjim commented 4 months ago

There's a similar test in tests/conformance/basic.lua, starting around line 729.

zeux commented 3 months ago

Yeah this predates the table invariant. I think these will need to be adjusted to find with an offset as that's the only case when indexing with an increasing sequence can access hash part now.