Commit Briefs

17f5251efb Sergey Bronnikov

test/fuzz: fix errors "table index is {nil, NaN}" (ligurio/fix-lua-errors)

Running of automatically generated Lua programs sometimes failed due to errors "table index is nil" and "table index is NaN" (3%). The error was caused by `nil` and `NaN` values used as a table indices and key values, but it is prohibited. Examples of errors are the following: ``` local t = {} t[nil] = 42 -- table index is nil. t[0 / 0] = 42 -- table index is NaN. local a = { [nil] = 0 } -- table index is nil. local a = { [0 / 0] = 0 } -- table index is NaN. ``` The patch fixes serializer, index or key value is always not a `nil` and not a `NaN`: it is either a generated value or a default number. NO_CHANGELOG=testing NO_DOC=testing NO_TEST=testing


229963a7d6 Sergey Bronnikov

test/fuzz: fix errors "'<name>' expected near 'and'"

Running of automatically generated Lua programs sometimes failed with an error "'<name>' expected near 'and'" (0.07%). Example of the error is the following: ```lua local t = {} t.or = 0 -- "'<name>' expected near 'or'" t.nil = 0 -- "'<name>' expected near 'nil'" t.not = 0 -- "'<name>' expected near 'not'" ``` This error was caused by reserved Lua keywords used as table indices. The patch fixes serializer, if the automatically generated index name is equal to the reserved keyword then postfix "_1" is added to index name. NO_CHANGELOG=testing NO_DOC=testing NO_TEST=testing


c3c00e1340 Sergey Bronnikov

test/fuzz: fix errors "attempt to compare"

Running of automatically generated Lua programs sometimes failed with an error "attempt to compare" (5%). The error is caused by comparison of non-comparable Lua values: string and boolean, number and function, boolean and number etc. In Lua 5.1 and LuaJIT 2.1 (which follow the semantics and behaviour of Lua 5.1), it is not possible to overload Lua metamethods __le and __lt for these base types. Therefore, an approach with metamethods doesn't help there. See an LuaJIT implementation in `src/lj_meta.c:lj_meta_comp()` and result of comparison values with different types and metamethods `__le` and `__lt`: ``` $ cat compare.lua local mt_table = {} mt_table.__le = function() assert() end mt_table.__lt = function() assert() end local res local str = 'str1' debug.setmetatable(str, mt_table) -- __le res = str <= 10 -- __lt res = str < 10 $ luajit compare.lua luajit: compare.lua:10: attempt to compare string with number stack traceback: compare.lua:10: in main chunk [C]: at 0x55908425f2e0 $ lua5.1 compare.lua lua5.1: compare.lua:10: attempt to compare string with number stack traceback: compare.lua:10: in main chunk [C]: ? $ lua5.2 compare.lua lua5.2: compare.lua:2: assertion failed! stack traceback: [C]: in function 'assert' compare.lua:2: in function '__le' compare.lua:10: in main chunk [C]: in ? $ ``` To fix errors triggered by comparison of non-comparable values introduced a metamethods `__le` and `__lt` and comparison operators are wrapped by a Lua function `only_numbers_cmp` that is implemented in `preamble.lua`. The function perform comparison only when both values have type 'number', otherwise it returns `false`. NO_CHANGELOG=testing NO_DOC=testing NO_TEST=testing


21a8675b02 Sergey Bronnikov

test/fuzz: fix a group of errors related to `for`

Running of automatically generated Lua programs sometimes failed with an errors like: - "'for' initial value must be a" (12%) - "'for' limit must be a" (4.5%) - "'for' step must be a" (0.4%) The patch fixes these errors. NO_CHANGELOG=testing NO_DOC=testing NO_TEST=testing


8e8866f786 Sergey Bronnikov

test/fuzz: fix errors "ambiguous syntax"

Running of automatically generated Lua programs sometimes failed with an error like "ambiguous syntax (function call x new statement)" (0.3%). The patch fixes these errors. NO_CHANGELOG=testing NO_DOC=testing NO_TEST=testing