Browse Source

Detail

Reports errors with "?:?:" (instead of "?:-1:") when there is no debug
information.
Roberto Ierusalimschy 2 months ago
parent
commit
f2c1531e6c
2 changed files with 7 additions and 8 deletions
  1. 5 6
      ldebug.c
  2. 2 2
      testes/errors.lua

+ 5 - 6
ldebug.c

@@ -817,16 +817,15 @@ l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
 /* add src:line information to 'msg' */
 /* add src:line information to 'msg' */
 const char *luaG_addinfo (lua_State *L, const char *msg, TString *src,
 const char *luaG_addinfo (lua_State *L, const char *msg, TString *src,
                                         int line) {
                                         int line) {
-  char buff[LUA_IDSIZE];
-  if (src) {
+  if (src == NULL)  /* no debug information? */
+    return luaO_pushfstring(L, "?:?: %s", msg);
+  else {
+    char buff[LUA_IDSIZE];
     size_t idlen;
     size_t idlen;
     const char *id = getlstr(src, idlen);
     const char *id = getlstr(src, idlen);
     luaO_chunkid(buff, id, idlen);
     luaO_chunkid(buff, id, idlen);
+    return luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
   }
   }
-  else {  /* no source available; use "?" instead */
-    buff[0] = '?'; buff[1] = '\0';
-  }
-  return luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
 }
 }
 
 
 
 

+ 2 - 2
testes/errors.lua

@@ -303,14 +303,14 @@ do
   local f = function (a) return a + 1 end
   local f = function (a) return a + 1 end
   f = assert(load(string.dump(f, true)))
   f = assert(load(string.dump(f, true)))
   assert(f(3) == 4)
   assert(f(3) == 4)
-  checkerr("^%?:%-1:", f, {})
+  checkerr("^%?:%?:", f, {})
 
 
   -- code with a move to a local var ('OP_MOV A B' with A<B)
   -- code with a move to a local var ('OP_MOV A B' with A<B)
   f = function () local a; a = {}; return a + 2 end
   f = function () local a; a = {}; return a + 2 end
   -- no debug info (so that 'a' is unknown)
   -- no debug info (so that 'a' is unknown)
   f = assert(load(string.dump(f, true)))
   f = assert(load(string.dump(f, true)))
   -- symbolic execution should not get lost
   -- symbolic execution should not get lost
-  checkerr("^%?:%-1:.*table value", f)
+  checkerr("^%?:%?:.*table value", f)
 end
 end