diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-18 12:03:54 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-18 12:03:54 -0300 |
| commit | 6d53701c7a0dc4736d824fd891ee6f22265d0d68 (patch) | |
| tree | 74876c6991b50c0327012e9cb9a3dc282925767d /testes/goto.lua | |
| parent | abbae57c7844b1121e7251d56f681394f20c1821 (diff) | |
| download | lua-6d53701c7a0dc4736d824fd891ee6f22265d0d68.tar.gz lua-6d53701c7a0dc4736d824fd891ee6f22265d0d68.tar.bz2 lua-6d53701c7a0dc4736d824fd891ee6f22265d0d68.zip | |
Proper error message when jumping into 'global *'
A goto cannot jump into the scope of any variable declaration,
including 'global *'. To report the error, it needs a "name" for
the scope it is entering.
Diffstat (limited to 'testes/goto.lua')
| -rw-r--r-- | testes/goto.lua | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/testes/goto.lua b/testes/goto.lua index 44486e20..d7730061 100644 --- a/testes/goto.lua +++ b/testes/goto.lua | |||
| @@ -23,15 +23,18 @@ errmsg([[ ::l1:: ::l1:: ]], "label 'l1'") | |||
| 23 | errmsg([[ ::l1:: do ::l1:: end]], "label 'l1'") | 23 | errmsg([[ ::l1:: do ::l1:: end]], "label 'l1'") |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | -- undefined label | ||
| 27 | errmsg([[ goto l1; local aa ::l1:: ::l2:: print(3) ]], "local 'aa'") | ||
| 28 | 26 | ||
| 29 | -- jumping over variable definition | 27 | -- jumping over variable declaration |
| 28 | errmsg([[ goto l1; local aa ::l1:: ::l2:: print(3) ]], "scope of 'aa'") | ||
| 29 | |||
| 30 | errmsg([[ goto l2; global *; ::l1:: ::l2:: print(3) ]], "scope of '*'") | ||
| 31 | |||
| 30 | errmsg([[ | 32 | errmsg([[ |
| 31 | do local bb, cc; goto l1; end | 33 | do local bb, cc; goto l1; end |
| 32 | local aa | 34 | local aa |
| 33 | ::l1:: print(3) | 35 | ::l1:: print(3) |
| 34 | ]], "local 'aa'") | 36 | ]], "scope of 'aa'") |
| 37 | |||
| 35 | 38 | ||
| 36 | -- jumping into a block | 39 | -- jumping into a block |
| 37 | errmsg([[ do ::l1:: end goto l1 ]], "label 'l1'") | 40 | errmsg([[ do ::l1:: end goto l1 ]], "label 'l1'") |
| @@ -44,7 +47,7 @@ errmsg([[ | |||
| 44 | local xuxu = 10 | 47 | local xuxu = 10 |
| 45 | ::cont:: | 48 | ::cont:: |
| 46 | until xuxu < x | 49 | until xuxu < x |
| 47 | ]], "local 'xuxu'") | 50 | ]], "scope of 'xuxu'") |
| 48 | 51 | ||
| 49 | -- simple gotos | 52 | -- simple gotos |
| 50 | local x | 53 | local x |
