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

using non int constant as array dimension #1451

Closed
mvertes opened this issue Sep 5, 2022 · 0 comments · Fixed by #1452
Closed

using non int constant as array dimension #1451

mvertes opened this issue Sep 5, 2022 · 0 comments · Fixed by #1452
Labels
area/core bug Something isn't working

Comments

@mvertes
Copy link
Member

mvertes commented Sep 5, 2022

The following program sample.go triggers an unexpected result

package main

type t1 uint8

const (
        n1 t1 = iota
        n2
)

type T struct {
        elem [n2 + 1]int
}

func main() {
        println(len(T{}.elem))
}

Expected result

$ go run ./sample.go
2

Got

$ yaegi ./sample.go
panic: reflect: call of reflect.Value.Int on uint8 Value

goroutine 1 [running]:
reflect.Value.Int(...)
        reflect/value.go:1459
github.com/traefik/yaegi/interp.nodeType2(0xc0000ed440, 0xc0000e8360, 0xc0003fafc0, {0xc0001a8f30, 0x1, 0x2})
        github.com/traefik/yaegi/interp/type.go:454 +0x79e6
github.com/traefik/yaegi/interp.nodeType2(0xc0000ed440, 0xc0000e8360, 0xc0003fab40, {0xc000014818, 0x0, 0x1})
        github.com/traefik/yaegi/interp/type.go:1034 +0x3b5e
github.com/traefik/yaegi/interp.nodeType(...)
        github.com/traefik/yaegi/interp/type.go:399
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc0003fa900)
        github.com/traefik/yaegi/interp/gta.go:308 +0x8ea
github.com/traefik/yaegi/interp.(*node).Walk(0xc0003fa900, 0xc00045b910, 0x0)
        github.com/traefik/yaegi/interp/interp.go:288 +0x34
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc0000ed440, 0xc0003fa900, {0xc0002d6bb0, 0x4}, {0xc0002d6bb0, 0x4}, {0xc0002d6bb0, 0x4})
        github.com/traefik/yaegi/interp/gta.go:20 +0x22b
github.com/traefik/yaegi/interp.(*Interpreter).gtaRetry(0xc0000ed440?, {0xc000187af0?, 0xc0000c8900?, 0xc000187a38?}, {0xc0002d6bb0, 0x4}, {0xc0002d6bb0, 0x4})
        github.com/traefik/yaegi/interp/gta.go:383 +0x154
github.com/traefik/yaegi/interp.(*Interpreter).CompileAST(0xc0000ed440, {0x557cc1815148?, 0xc0000c8900?})
        github.com/traefik/yaegi/interp/program.go:87 +0x17f
github.com/traefik/yaegi/interp.(*Interpreter).compileSrc(0xc0000ed440, {0xc0002a0b40?, 0x0?}, {0x7ffe60aa69d7?, 0xc0002a0b40?}, 0x98?)
        github.com/traefik/yaegi/interp/program.go:59 +0xb8
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc0000ed440, {0xc0002a0b40?, 0x98?}, {0x7ffe60aa69d7?, 0xc0002a0a00?}, 0x98?)
        github.com/traefik/yaegi/interp/interp.go:612 +0x28
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0xc0000ed440, {0x7ffe60aa69d7, 0x1d})
        github.com/traefik/yaegi/interp/interp.go:514 +0xab
main.runFile(0x7ffe60aa69d7?, {0x7ffe60aa69d7, 0x1d}, 0x0)
        github.com/traefik/yaegi/cmd/yaegi/run.go:153 +0xee
main.run({0xc000036050?, 0x1, 0x1})
        github.com/traefik/yaegi/cmd/yaegi/run.go:116 +0xbec
main.main()
        github.com/traefik/yaegi/cmd/yaegi/yaegi.go:144 +0x2cb

Yaegi Version

v0.14.2

Additional Notes

This issue is related to #1419.

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.

1 participant