MCPcopy Index your code
hub / github.com/yuin/gopher-lua / TestMergingLoadNilBug2

Function TestMergingLoadNilBug2

script_test.go:150–175  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

148}
149
150func 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
177func TestMergingLoadNilBug(t *testing.T) {
178 // there was a bug where a multiple load nils were being incorrectly merged, and the following code exposed it

Callers

nothing calls this directly

Calls 4

DoStringMethod · 0.80
NewStateFunction · 0.70
ErrorMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…