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

Errors handling slice/array type parameters #1488

Closed
vsivsi opened this issue Nov 4, 2022 · 0 comments · Fixed by #1489
Closed

Errors handling slice/array type parameters #1488

vsivsi opened this issue Nov 4, 2022 · 0 comments · Fixed by #1489
Labels
area/core bug Something isn't working
Milestone

Comments

@vsivsi
Copy link

vsivsi commented Nov 4, 2022

The following program sample.go triggers an unexpected result

package main

import "fmt"

type vector interface {
	[]int | [3]int
}

func sum[V vector](v V) (out int) {
	for i := 0; i < len(v); i++ {
		out += v[i]
	}
	return
}

func main() {
	va := [3]int{1, 2, 3}
	vs := []int{1, 2, 3}
	fmt.Println(sum[[3]int](va), sum[[]int](vs))
}

Expected result

6 6

Got

panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: sample.go:19:14: CFG post-order panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2.1()
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/cfg.go:536 +0x78
panic({0x1a54180, 0xc000040060})
	/usr/local/Cellar/go/1.19.3/libexec/src/runtime/panic.go:890 +0x262
github.com/traefik/yaegi/interp.nodeType2(0xc0002e6000, 0xc0002ee090, 0xc000421320, {0xc000099390, 0x1, 0x2})
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/type.go:432 +0x7c4f
github.com/traefik/yaegi/interp.nodeType2(0xc0002e6000, 0xc0002ee090, 0xc000420c60, {0xc000014388, 0x0, 0x1})
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/type.go:739 +0x63e6
github.com/traefik/yaegi/interp.nodeType(0x8?, 0xc000099370?, 0x1?)
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/type.go:399 +0x25
github.com/traefik/yaegi/interp.(*Interpreter).cfg.func1(0xc000420900)
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/cfg.go:407 +0x1a79
github.com/traefik/yaegi/interp.(*node).Walk(0xc000420900, 0xc00041ea90, 0xc00041ead8)
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/interp.go:284 +0x34
github.com/traefik/yaegi/interp.(*Interpreter).cfg(0xc0002e6000, 0xc000420900, 0xc0002ee090, {0xc00003fa48, 0x4}, {0xc00003fa48, 0x4})
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/cfg.go:62 +0x2b4
github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2(0xc0004165a0)
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/cfg.go:878 +0x9c08
github.com/traefik/yaegi/interp.(*node).Walk(0xc0004165a0, 0xc00041f990, 0xc00041f9d8)
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/interp.go:291 +0xad
github.com/traefik/yaegi/interp.(*node).Walk(0xc000416480, 0xc00041f990, 0xc00041f9d8)
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc000416000, 0xc00041f990, 0xc00041f9d8)
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc000415e60, 0xc00041f990, 0xc00041f9d8)
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc000414a20, 0xc00041f990, 0xc00041f9d8)
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc000414360, 0xc00041f990, 0xc00041f9d8)
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc0002f07e0, 0xc00041f990, 0xc00041f9d8)
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*Interpreter).cfg(0xc0002e6000, 0xc0002f07e0, 0xc0002ee1b0, {0xc00003fa48, 0x4}, {0xc00003fa48, 0x4})
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/cfg.go:62 +0x2b4
github.com/traefik/yaegi/interp.(*Interpreter).CompileAST(0xc0002e6000, {0x1c8a7a8?, 0xc0002a4100?})
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/program.go:92 +0x1ad
github.com/traefik/yaegi/interp.(*Interpreter).compileSrc(0xc0002e6000, {0xc0002ae480?, 0x0?}, {0x7ffeefbffc06?, 0xc0002ae480?}, 0x13?)
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/program.go:59 +0xb8
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc0002e6000, {0xc0002ae480?, 0x113?}, {0x7ffeefbffc06?, 0xc0002ae240?}, 0x13?)
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/interp.go:552 +0x28
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0xc0002e6000, {0x7ffeefbffc06, 0x7})
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/interp/interp.go:510 +0xab
main.runFile(0x7ffeefbffc06?, {0x7ffeefbffc06, 0x7}, 0x0)
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/cmd/yaegi/run.go:153 +0xee
main.run({0xc00019a010?, 0x1, 0x1})
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/cmd/yaegi/run.go:116 +0xbec
main.main()
	/Users/vsi/go/pkg/mod/github.com/traefik/yaegi@v0.14.3/cmd/yaegi/yaegi.go:144 +0x2cb

Yaegi Version

v0.14.3

Additional Notes

No response

@mvertes mvertes added bug Something isn't working area/core labels Nov 8, 2022
mvertes added a commit to mvertes/yaegi that referenced this issue Nov 16, 2022
When generating a new type, the parameter type was not correctly
duplicated in the new AST. This is fixed by making copyNode recursive
if needed. The out of order processing of generic types has also been
fixed.

Fixes traefik#1488.
ldez pushed a commit to mvertes/yaegi that referenced this issue Feb 3, 2023
When generating a new type, the parameter type was not correctly
duplicated in the new AST. This is fixed by making copyNode recursive
if needed. The out of order processing of generic types has also been
fixed.

Fixes traefik#1488.
@traefiker traefiker added this to the v0.15.x milestone Feb 8, 2023
traefiker pushed a commit that referenced this issue Feb 8, 2023
When generating a new type, the parameter type was not correctly duplicated in the new AST. This is fixed by making copyNode recursive if needed. The out of order processing of generic types has also been fixed.

Fixes #1488
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants