aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-02-28 14:53:58 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-02-28 14:53:58 -0300
commitee99452158de5e2fa804bd10de7669848f3b3952 (patch)
treea68b8834ef0f61f9a7a2ce297ab3963cec8e56d9 /testes
parent127a8e80fe0d74efd26994b3877cdc77b712ea56 (diff)
downloadlua-ee99452158de5e2fa804bd10de7669848f3b3952.tar.gz
lua-ee99452158de5e2fa804bd10de7669848f3b3952.tar.bz2
lua-ee99452158de5e2fa804bd10de7669848f3b3952.zip
Error object cannot be nil
Lua will change a nil as error object to a string message, so that it never reports an error with nil as the error object.
Diffstat (limited to 'testes')
-rw-r--r--testes/errors.lua6
1 files changed, 3 insertions, 3 deletions
diff --git a/testes/errors.lua b/testes/errors.lua
index adc111fd..5fdb7722 100644
--- a/testes/errors.lua
+++ b/testes/errors.lua
@@ -46,7 +46,7 @@ end
46assert(doit("error('hi', 0)") == 'hi') 46assert(doit("error('hi', 0)") == 'hi')
47 47
48-- test nil error message 48-- test nil error message
49assert(doit("error()") == nil) 49assert(doit("error()") == "<error object is nil>")
50 50
51 51
52-- test common errors/errors that crashed in the past 52-- test common errors/errors that crashed in the past
@@ -614,7 +614,7 @@ do
614 assert(not res and msg == t) 614 assert(not res and msg == t)
615 615
616 res, msg = pcall(function () error(nil) end) 616 res, msg = pcall(function () error(nil) end)
617 assert(not res and msg == nil) 617 assert(not res and msg == "<error object is nil>")
618 618
619 local function f() error{msg='x'} end 619 local function f() error{msg='x'} end
620 res, msg = xpcall(f, function (r) return {msg=r.msg..'y'} end) 620 res, msg = xpcall(f, function (r) return {msg=r.msg..'y'} end)
@@ -634,7 +634,7 @@ do
634 assert(not res and msg == t) 634 assert(not res and msg == t)
635 635
636 res, msg = pcall(assert, nil, nil) 636 res, msg = pcall(assert, nil, nil)
637 assert(not res and msg == nil) 637 assert(not res and type(msg) == "string")
638 638
639 -- 'assert' without arguments 639 -- 'assert' without arguments
640 res, msg = pcall(assert) 640 res, msg = pcall(assert)