diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-16 15:20:32 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-16 15:20:32 -0300 |
commit | f2c1531e6cacb10926158d8def5fa5841a0f357e (patch) | |
tree | 2d97fc65c95765f8238892a8817abaec35d944fc | |
parent | ded2ad2d86f44424c6b6e12bf1b75836cfa9e502 (diff) | |
download | lua-f2c1531e6cacb10926158d8def5fa5841a0f357e.tar.gz lua-f2c1531e6cacb10926158d8def5fa5841a0f357e.tar.bz2 lua-f2c1531e6cacb10926158d8def5fa5841a0f357e.zip |
Detail
Reports errors with "?:?:" (instead of "?:-1:") when there is no debug
information.
-rw-r--r-- | ldebug.c | 11 | ||||
-rw-r--r-- | testes/errors.lua | 4 |
2 files changed, 7 insertions, 8 deletions
@@ -817,16 +817,15 @@ l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { | |||
817 | /* add src:line information to 'msg' */ | 817 | /* add src:line information to 'msg' */ |
818 | const char *luaG_addinfo (lua_State *L, const char *msg, TString *src, | 818 | const char *luaG_addinfo (lua_State *L, const char *msg, TString *src, |
819 | int line) { | 819 | int line) { |
820 | char buff[LUA_IDSIZE]; | 820 | if (src == NULL) /* no debug information? */ |
821 | if (src) { | 821 | return luaO_pushfstring(L, "?:?: %s", msg); |
822 | else { | ||
823 | char buff[LUA_IDSIZE]; | ||
822 | size_t idlen; | 824 | size_t idlen; |
823 | const char *id = getlstr(src, idlen); | 825 | const char *id = getlstr(src, idlen); |
824 | luaO_chunkid(buff, id, idlen); | 826 | luaO_chunkid(buff, id, idlen); |
827 | return luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); | ||
825 | } | 828 | } |
826 | else { /* no source available; use "?" instead */ | ||
827 | buff[0] = '?'; buff[1] = '\0'; | ||
828 | } | ||
829 | return luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); | ||
830 | } | 829 | } |
831 | 830 | ||
832 | 831 | ||
diff --git a/testes/errors.lua b/testes/errors.lua index 6c76a99a..a0728913 100644 --- a/testes/errors.lua +++ b/testes/errors.lua | |||
@@ -303,14 +303,14 @@ do | |||
303 | local f = function (a) return a + 1 end | 303 | local f = function (a) return a + 1 end |
304 | f = assert(load(string.dump(f, true))) | 304 | f = assert(load(string.dump(f, true))) |
305 | assert(f(3) == 4) | 305 | assert(f(3) == 4) |
306 | checkerr("^%?:%-1:", f, {}) | 306 | checkerr("^%?:%?:", f, {}) |
307 | 307 | ||
308 | -- code with a move to a local var ('OP_MOV A B' with A<B) | 308 | -- code with a move to a local var ('OP_MOV A B' with A<B) |
309 | f = function () local a; a = {}; return a + 2 end | 309 | f = function () local a; a = {}; return a + 2 end |
310 | -- no debug info (so that 'a' is unknown) | 310 | -- no debug info (so that 'a' is unknown) |
311 | f = assert(load(string.dump(f, true))) | 311 | f = assert(load(string.dump(f, true))) |
312 | -- symbolic execution should not get lost | 312 | -- symbolic execution should not get lost |
313 | checkerr("^%?:%-1:.*table value", f) | 313 | checkerr("^%?:%?:.*table value", f) |
314 | end | 314 | end |
315 | 315 | ||
316 | 316 | ||