aboutsummaryrefslogtreecommitdiff
path: root/testes/errors.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-12-29 13:15:54 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-12-29 13:15:54 -0300
commit4bd10b6fe81c0a56eb9e01e24fba10e655966870 (patch)
treeff21703d9f06a0dd4ca4f3317dd0cb7b048c9b8d /testes/errors.lua
parent59e565d9555c07e82808d8c1db8f4f4d159b5e5c (diff)
downloadlua-4bd10b6fe81c0a56eb9e01e24fba10e655966870.tar.gz
lua-4bd10b6fe81c0a56eb9e01e24fba10e655966870.tar.bz2
lua-4bd10b6fe81c0a56eb9e01e24fba10e655966870.zip
Better error messages for calling non-callable objects
When available, use the calling code to find a suitable name for what was being called; this is particularly useful for errors of non-callable metamethods. This commit also improved the debug information for order metamethods.
Diffstat (limited to 'testes/errors.lua')
-rw-r--r--testes/errors.lua14
1 files changed, 13 insertions, 1 deletions
diff --git a/testes/errors.lua b/testes/errors.lua
index a3f07021..4249f570 100644
--- a/testes/errors.lua
+++ b/testes/errors.lua
@@ -24,8 +24,9 @@ local function doit (s)
24end 24end
25 25
26 26
27local function checkmessage (prog, msg) 27local function checkmessage (prog, msg, debug)
28 local m = doit(prog) 28 local m = doit(prog)
29 if debug then print(m) end
29 assert(string.find(m, msg, 1, true)) 30 assert(string.find(m, msg, 1, true))
30end 31end
31 32
@@ -120,6 +121,17 @@ assert(not string.find(doit"a={13}; local bbbb=1; a[bbbb](3)", "'bbbb'"))
120checkmessage("a={13}; local bbbb=1; a[bbbb](3)", "number") 121checkmessage("a={13}; local bbbb=1; a[bbbb](3)", "number")
121checkmessage("a=(1)..{}", "a table value") 122checkmessage("a=(1)..{}", "a table value")
122 123
124-- calls
125checkmessage("local a; a(13)", "local 'a'")
126checkmessage([[
127 local a = setmetatable({}, {__add = 34})
128 a = a + 1
129]], "metamethod 'add'")
130checkmessage([[
131 local a = setmetatable({}, {__lt = {}})
132 a = a > a
133]], "metamethod 'lt'")
134
123-- tail calls 135-- tail calls
124checkmessage("local a={}; return a.bbbb(3)", "field 'bbbb'") 136checkmessage("local a={}; return a.bbbb(3)", "field 'bbbb'")
125checkmessage("a={}; do local a=1 end; return a:bbbb(3)", "method 'bbbb'") 137checkmessage("a={}; do local a=1 end; return a:bbbb(3)", "method 'bbbb'")