| 148 | } |
| 149 | |
| 150 | func TestMergingLoadNilBug2(t *testing.T) { |
| 151 | // there was a bug where the LOADNIL merging optimisation would merge LOADNILs that were the targets of |
| 152 | // JMP instructions, causing the JMP to jump to the wrong location and breaking the logic and resulting in |
| 153 | // a panic. |
| 154 | s := ` |
| 155 | id = "foo" |
| 156 | |
| 157 | function get_def() |
| 158 | return {} |
| 159 | end |
| 160 | |
| 161 | function test() |
| 162 | local def = id ~= nil and get_def() or nil |
| 163 | if def ~= nil then |
| 164 | print("def is not nil") |
| 165 | end |
| 166 | end |
| 167 | |
| 168 | test() |
| 169 | ` |
| 170 | L := NewState() |
| 171 | defer L.Close() |
| 172 | if err := L.DoString(s); err != nil { |
| 173 | t.Error(err) |
| 174 | } |
| 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 |