diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-05 13:16:25 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-05 13:16:25 -0300 |
| commit | b4d5dff8ec4f1c8a44db66d368e95d359b04aea7 (patch) | |
| tree | e87fbd3bcbf8a271429ee31f32eaf928058ab376 /testes/coroutine.lua | |
| parent | 14edd364c3abcb758e74c68a2bdd4ddaeefdae2a (diff) | |
| download | lua-b4d5dff8ec4f1c8a44db66d368e95d359b04aea7.tar.gz lua-b4d5dff8ec4f1c8a44db66d368e95d359b04aea7.tar.bz2 lua-b4d5dff8ec4f1c8a44db66d368e95d359b04aea7.zip | |
Multiple errors in '__toclose' report the first one
When there are multiple errors when closing objects, the error
reported by the protected call is the first one, for two reasons:
First, other errors may be caused by this one;
second, the first error is handled in the original execution context,
and therefore has the full traceback.
Diffstat (limited to 'testes/coroutine.lua')
| -rw-r--r-- | testes/coroutine.lua | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/testes/coroutine.lua b/testes/coroutine.lua index 198a5870..f2c0da8b 100644 --- a/testes/coroutine.lua +++ b/testes/coroutine.lua | |||
| @@ -163,15 +163,23 @@ do | |||
| 163 | assert(not X and coroutine.status(co) == "dead") | 163 | assert(not X and coroutine.status(co) == "dead") |
| 164 | 164 | ||
| 165 | -- error closing a coroutine | 165 | -- error closing a coroutine |
| 166 | local x = 0 | ||
| 166 | co = coroutine.create(function() | 167 | co = coroutine.create(function() |
| 168 | local <toclose> y = func2close(function (self,err) | ||
| 169 | if (err ~= 111) then os.exit(false) end -- should not happen | ||
| 170 | x = 200 | ||
| 171 | error(200) | ||
| 172 | end) | ||
| 167 | local <toclose> x = func2close(function (self, err) | 173 | local <toclose> x = func2close(function (self, err) |
| 168 | assert(err == nil); error(111) | 174 | assert(err == nil); error(111) |
| 169 | end) | 175 | end) |
| 170 | coroutine.yield() | 176 | coroutine.yield() |
| 171 | end) | 177 | end) |
| 172 | coroutine.resume(co) | 178 | coroutine.resume(co) |
| 179 | assert(x == 0) | ||
| 173 | local st, msg = coroutine.close(co) | 180 | local st, msg = coroutine.close(co) |
| 174 | assert(not st and coroutine.status(co) == "dead" and msg == 111) | 181 | assert(st == false and coroutine.status(co) == "dead" and msg == 111) |
| 182 | assert(x == 200) | ||
| 175 | 183 | ||
| 176 | end | 184 | end |
| 177 | 185 | ||
