| 175 | } |
| 176 | |
| 177 | func TestMergingLoadNilBug(t *testing.T) { |
| 178 | // there was a bug where a multiple load nils were being incorrectly merged, and the following code exposed it |
| 179 | s := ` |
| 180 | function test() |
| 181 | local a = 0 |
| 182 | local b = 1 |
| 183 | local c = 2 |
| 184 | local d = 3 |
| 185 | local e = 4 -- reg 4 |
| 186 | local f = 5 |
| 187 | local g = 6 |
| 188 | local h = 7 |
| 189 | |
| 190 | if e == 4 then |
| 191 | e = nil -- should clear reg 4, but clears regs 4-8 by mistake |
| 192 | end |
| 193 | if f == nil then |
| 194 | error("bad f") |
| 195 | end |
| 196 | if g == nil then |
| 197 | error("bad g") |
| 198 | end |
| 199 | if h == nil then |
| 200 | error("bad h") |
| 201 | end |
| 202 | end |
| 203 | |
| 204 | test() |
| 205 | ` |
| 206 | |
| 207 | L := NewState() |
| 208 | defer L.Close() |
| 209 | if err := L.DoString(s); err != nil { |
| 210 | t.Error(err) |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | // This test is disabled because the LOADNIL merging optimisation has been disabled. See the comment in the |
| 215 | // AddLoadNil() function for more information. |