diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-12-21 12:04:59 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-12-21 12:04:59 -0300 |
| commit | b2f7b3b79f3117885b265575f6c5dbf934757797 (patch) | |
| tree | ad7ac30fb9a05e1e6635110f03c45b9cd41190c8 /testes/nextvar.lua | |
| parent | 540d8052265776451bb9f0ab4dee4ec860563cbe (diff) | |
| download | lua-b2f7b3b79f3117885b265575f6c5dbf934757797.tar.gz lua-b2f7b3b79f3117885b265575f6c5dbf934757797.tar.bz2 lua-b2f7b3b79f3117885b265575f6c5dbf934757797.zip | |
Control variables in for loops are read only
Diffstat (limited to 'testes/nextvar.lua')
| -rw-r--r-- | testes/nextvar.lua | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/testes/nextvar.lua b/testes/nextvar.lua index 80b3d05c..87910ef9 100644 --- a/testes/nextvar.lua +++ b/testes/nextvar.lua | |||
| @@ -609,10 +609,12 @@ do | |||
| 609 | a = 0; for i=1.0, 0.99999, -1 do a=a+1 end; assert(a==1) | 609 | a = 0; for i=1.0, 0.99999, -1 do a=a+1 end; assert(a==1) |
| 610 | end | 610 | end |
| 611 | 611 | ||
| 612 | do -- changing the control variable | 612 | do -- attempt to change the control variable |
| 613 | local a | 613 | local st, msg = load "for i = 1, 10 do i = 10 end" |
| 614 | a = 0; for i = 1, 10 do a = a + 1; i = "x" end; assert(a == 10) | 614 | assert(not st and string.find(msg, "assign to const variable 'i'")) |
| 615 | a = 0; for i = 10.0, 1, -1 do a = a + 1; i = "x" end; assert(a == 10) | 615 | |
| 616 | local st, msg = load "for v, k in pairs{} do v = 10 end" | ||
| 617 | assert(not st and string.find(msg, "assign to const variable 'v'")) | ||
| 616 | end | 618 | end |
| 617 | 619 | ||
| 618 | -- conversion | 620 | -- conversion |
