From e0260eb2d4085723302d637dd8f3fca339d18817 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 25 Feb 2021 13:39:36 -0300 Subject: Bug (kind of) in 'isinstack' The function 'isinstack' tried to work around the undefined behavior of subtracting two pointers that do not point to the same object, but the compiler killed to trick. (It optimizes out the safety check, because in a correct execution it will be always true.) --- testes/errors.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'testes/errors.lua') diff --git a/testes/errors.lua b/testes/errors.lua index 4249f570..fd02806e 100644 --- a/testes/errors.lua +++ b/testes/errors.lua @@ -191,6 +191,13 @@ checkmessage("a = 24 // 0", "divide by zero") checkmessage("a = 1 % 0", "'n%0'") +-- type error for an object which is neither in an upvalue nor a register. +-- The following code will try to index the value 10 that is stored in +-- the metatable, without moving it to a register. +checkmessage("local a = setmetatable({}, {__index = 10}).x", + "attempt to index a number value") + + -- numeric for loops checkmessage("for i = {}, 10 do end", "table") checkmessage("for i = io.stdin, 10 do end", "FILE") -- cgit v1.2.3-55-g6feb