diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-12-29 13:15:54 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-12-29 13:15:54 -0300 |
commit | 4bd10b6fe81c0a56eb9e01e24fba10e655966870 (patch) | |
tree | ff21703d9f06a0dd4ca4f3317dd0cb7b048c9b8d /testes/errors.lua | |
parent | 59e565d9555c07e82808d8c1db8f4f4d159b5e5c (diff) | |
download | lua-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.lua | 14 |
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) | |||
24 | end | 24 | end |
25 | 25 | ||
26 | 26 | ||
27 | local function checkmessage (prog, msg) | 27 | local 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)) |
30 | end | 31 | end |
31 | 32 | ||
@@ -120,6 +121,17 @@ assert(not string.find(doit"a={13}; local bbbb=1; a[bbbb](3)", "'bbbb'")) | |||
120 | checkmessage("a={13}; local bbbb=1; a[bbbb](3)", "number") | 121 | checkmessage("a={13}; local bbbb=1; a[bbbb](3)", "number") |
121 | checkmessage("a=(1)..{}", "a table value") | 122 | checkmessage("a=(1)..{}", "a table value") |
122 | 123 | ||
124 | -- calls | ||
125 | checkmessage("local a; a(13)", "local 'a'") | ||
126 | checkmessage([[ | ||
127 | local a = setmetatable({}, {__add = 34}) | ||
128 | a = a + 1 | ||
129 | ]], "metamethod 'add'") | ||
130 | checkmessage([[ | ||
131 | local a = setmetatable({}, {__lt = {}}) | ||
132 | a = a > a | ||
133 | ]], "metamethod 'lt'") | ||
134 | |||
123 | -- tail calls | 135 | -- tail calls |
124 | checkmessage("local a={}; return a.bbbb(3)", "field 'bbbb'") | 136 | checkmessage("local a={}; return a.bbbb(3)", "field 'bbbb'") |
125 | checkmessage("a={}; do local a=1 end; return a:bbbb(3)", "method 'bbbb'") | 137 | checkmessage("a={}; do local a=1 end; return a:bbbb(3)", "method 'bbbb'") |