Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: runtime error: slice bounds out of range [1:0] #1649

Open
muazhari opened this issue Jul 17, 2024 · 0 comments
Open

panic: runtime error: slice bounds out of range [1:0] #1649

muazhari opened this issue Jul 17, 2024 · 0 comments

Comments

@muazhari
Copy link

The following program sample.go triggers an unexpected result

package main


import (
	"fmt"
	"github.com/traefik/yaegi/interp"
	"math"
)

func main() {
	c0Str := `
func c0(args ...any) (result any) {
	fmt.Println("c0")
	n := args[0].(int64)
	count := int64(0)
	for i := int64(1); i < n; i++ {
		for j := int64(1); j < (i * i); j++ {
			count += 1
		}
	}
	return count
}
`

	c1Str := `
func c1(args ...any) (result any) {
	fmt.Println("c1")
	count := int64(0)
	for i := int64(1); i < int64(math.Log2(float64(n))); i++ {
		for j := int64(1); j < n-i; j++ {
			count += 1
		}
	}
	return count
}
`
	i := interp.New(interp.Options{})

	_, _ = i.Eval(`
import 
(
	"fmt"
	"math"
)
`)
	_, _ = i.Eval(c0Str)
	_, _ = i.Eval(c1Str)
	c0v, _ := i.Eval("c0")
	c1v, _ := i.Eval("c1")

	c0I := c0v.Interface().(func(...any) any)
	c1I := c1v.Interface().(func(...any) any)

	c0F := c0I(int64(100))
	c1F := c1I(int64(100))

	fmt.Println(c0F)
	fmt.Println(c1F)
}

Expected result

some integer
some integer

Got

panic: runtime error: slice bounds out of range [1:0]

goroutine 1 [running]:
github.com/traefik/yaegi/interp.genFunctionWrapper.func1.1({0xc000012420, 0x1, 0x1?})
        /home/muazhari/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/run.go:1000 +0x7f4
main.main()
        /mnt/c/Data/Apps/golang/main.go:266 +0x2c3
exit status 2

Yaegi Version

v0.16.1

Additional Notes

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant