traefik / yaegi

Yaegi is Another Elegant Go Interpreter
https://pkg.go.dev/github.com/traefik/yaegi
Apache License 2.0
7.02k stars 348 forks source link

crash when assigning to underscore #1619

Closed poolpOrg closed 6 months ago

poolpOrg commented 6 months ago

The following program sample.go triggers an unexpected result

package main

func main() {
    _ = 1 + 1
}

Expected result

nothing

Got

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: pocleak.go:34:6: CFG post-order panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x10517db74]

goroutine 1 [running]:
github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2.1()
        /Users/gilles/Wip/github.com/traefik/yaegi/interp/cfg.go:536 +0x78
panic({0x105884e40?, 0x105e664c0?})
        /usr/local/go/src/runtime/panic.go:920 +0x26c
github.com/traefik/yaegi/interp.isEmptyInterface(...)
        /Users/gilles/Wip/github.com/traefik/yaegi/interp/type.go:2294
github.com/traefik/yaegi/interp.nodeType2(0x1400014b680, 0x14000174900, 0x14000361b00, {0x140000729c8, 0x0, 0x1})
        /Users/gilles/Wip/github.com/traefik/yaegi/interp/type.go:584 +0x52e4
github.com/traefik/yaegi/interp.nodeType(0x105878000?, 0x14000361b00?, 0x1056153de?)
        /Users/gilles/Wip/github.com/traefik/yaegi/interp/type.go:399 +0x28
github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2(0x14000361b00)
        /Users/gilles/Wip/github.com/traefik/yaegi/interp/cfg.go:811 +0x7e4
github.com/traefik/yaegi/interp.(*node).Walk(0x14000361b00, 0x14000351888, 0x140003518d0)
        /Users/gilles/Wip/github.com/traefik/yaegi/interp/interp.go:291 +0xa8
github.com/traefik/yaegi/interp.(*node).Walk(0x140003618c0, 0x14000351888, 0x140003518d0)
        /Users/gilles/Wip/github.com/traefik/yaegi/interp/interp.go:288 +0x74
github.com/traefik/yaegi/interp.(*node).Walk(0x140003617a0, 0x14000351888, 0x140003518d0)
        /Users/gilles/Wip/github.com/traefik/yaegi/interp/interp.go:288 +0x74
github.com/traefik/yaegi/interp.(*node).Walk(0x140003610e0, 0x14000351888, 0x140003518d0)
        /Users/gilles/Wip/github.com/traefik/yaegi/interp/interp.go:288 +0x74
github.com/traefik/yaegi/interp.(*node).Walk(0x14000257680, 0x14000351888, 0x140003518d0)
        /Users/gilles/Wip/github.com/traefik/yaegi/interp/interp.go:288 +0x74
github.com/traefik/yaegi/interp.(*Interpreter).cfg(0x1400014b680, 0x14000257680, 0x14000174900, {0x14000234158, 0x4}, {0x14000234158, 0x4})
        /Users/gilles/Wip/github.com/traefik/yaegi/interp/cfg.go:62 +0x198
github.com/traefik/yaegi/interp.(*Interpreter).CompileAST(0x1400014b680, {0x1059776a0?, 0x140001257c0?})
        /Users/gilles/Wip/github.com/traefik/yaegi/interp/program.go:92 +0x148
github.com/traefik/yaegi/interp.(*Interpreter).compileSrc(0x1400014b680, {0x14000346780?, 0x25f?}, {0x16b00b3b0?, 0x14000072400?}, 0x80?)
        /Users/gilles/Wip/github.com/traefik/yaegi/interp/program.go:59 +0xb8
github.com/traefik/yaegi/interp.(*Interpreter).eval(0x1400014b680, {0x14000346780?, 0x25f?}, {0x16b00b3b0?, 0x200?}, 0x80?)
        /Users/gilles/Wip/github.com/traefik/yaegi/interp/interp.go:552 +0x28
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0x1400014b680, {0x16b00b3b0, 0x7b})
        /Users/gilles/Wip/github.com/traefik/yaegi/interp/interp.go:510 +0xa4
main.runFile(0x16b00b3b0?, {0x16b00b3b0, 0x7b}, 0x0)
        /Users/gilles/Wip/github.com/traefik/yaegi/cmd/yaegi/run.go:153 +0xe8
main.run({0x14000032050?, 0x1, 0x1})
        /Users/gilles/Wip/github.com/traefik/yaegi/cmd/yaegi/run.go:116 +0xaf8
main.main()
        /Users/gilles/Wip/github.com/traefik/yaegi/cmd/yaegi/yaegi.go:144 +0x308

Yaegi Version

main branch

Additional Notes

This triggers for any binary expression assigned to _