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

assign from shift #917

Closed
mvertes opened this issue Oct 22, 2020 · 0 comments · Fixed by #918
Closed

assign from shift #917

mvertes opened this issue Oct 22, 2020 · 0 comments · Fixed by #918
Assignees
Labels
area/core bug Something isn't working
Milestone

Comments

@mvertes
Copy link
Member

mvertes commented Oct 22, 2020

The following program sample.go triggers a panic:

package main

type H struct {
    bits uint
}

func main() {
    h := &H{8}
    var x uint = (1 << h.bits) >> 6

    println(x)
}

Expected result:

$ go run ./sample.go
4

Got:

$ yaegi ./sample.go
run: ./sample.go:9:15: CFG post-order panic: reflect: call of reflect.Value.Interface on zero Value
goroutine 1 [running]:
runtime/debug.Stack(0x1, 0xc0002e0600, 0x40)
        /usr/lib/go/src/runtime/debug/stack.go:24 +0x9f
github.com/traefik/yaegi/interp.(*Interpreter).eval.func1(0xc0001e3c70)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:480 +0xc5
panic(0xeab440, 0xc000209020)
        /usr/lib/go/src/runtime/panic.go:969 +0x175
github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2.1(0xc000463b00)
        /home/marc/go/src/github.com/traefik/yaegi/interp/cfg.go:424 +0xb3
panic(0xe01b20, 0xc000208fe0)
        /usr/lib/go/src/runtime/panic.go:969 +0x175
reflect.valueInterface(0x0, 0x0, 0x0, 0x10a1601, 0xdccd60, 0x1)
        /usr/lib/go/src/reflect/value.go:1020 +0x1ad
reflect.Value.Interface(...)
        /usr/lib/go/src/reflect/value.go:1015
github.com/traefik/yaegi/interp.typecheck.shift(0xc000463b00, 0x7fafa5972280, 0x0)
        /home/marc/go/src/github.com/traefik/yaegi/interp/typecheck.go:152 +0x552
github.com/traefik/yaegi/interp.typecheck.binaryExpr(0xc000463b00, 0xc00030a960, 0xef901c)
        /home/marc/go/src/github.com/traefik/yaegi/interp/typecheck.go:223 +0x547
github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2(0xc000463b00)
        /home/marc/go/src/github.com/traefik/yaegi/interp/cfg.go:633 +0x8ffd
github.com/traefik/yaegi/interp.(*node).Walk(0xc000463b00, 0xc0001e3af0, 0xc0001e3ac0)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:220 +0xa5
github.com/traefik/yaegi/interp.(*node).Walk(0xc000463800, 0xc0001e3af0, 0xc0001e3ac0)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:217 +0x66
github.com/traefik/yaegi/interp.(*node).Walk(0xc000463700, 0xc0001e3af0, 0xc0001e3ac0)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:217 +0x66
github.com/traefik/yaegi/interp.(*node).Walk(0xc000463600, 0xc0001e3af0, 0xc0001e3ac0)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:217 +0x66
github.com/traefik/yaegi/interp.(*node).Walk(0xc000462f00, 0xc0001e3af0, 0xc0001e3ac0)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:217 +0x66
github.com/traefik/yaegi/interp.(*node).Walk(0xc000462a00, 0xc0001e3af0, 0xc0001e3ac0)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:217 +0x66
github.com/traefik/yaegi/interp.(*node).Walk(0xc000462000, 0xc0001e3af0, 0xc0001e3ac0)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:217 +0x66
github.com/traefik/yaegi/interp.(*Interpreter).cfg(0xc00035e000, 0xc000462000, 0xc0002178e8, 0x4, 0xc0002178e8, 0x4, 0x0, 0x0, 0xc000462000)
        /home/marc/go/src/github.com/traefik/yaegi/interp/cfg.go:63 +0x20f
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc00035e000, 0xc0002babd0, 0x87, 0x7ffc443d9498, 0x19, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:507 +0x2f3
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0xc00035e000, 0x7ffc443d9498, 0x19, 0xc0002bab00, 0x87, 0x0, 0x0, 0xc000212c30)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:394 +0xfa
main.runFile(0xc00035e000, 0x7ffc443d9498, 0x19, 0xc000200180, 0x1)
        /home/marc/go/src/github.com/traefik/yaegi/cmd/yaegi/run.go:123 +0xae
main.run(0xc000128030, 0x1, 0x1, 0x13, 0x13)
        /home/marc/go/src/github.com/traefik/yaegi/cmd/yaegi/run.go:89 +0x7e5
main.main()
        /home/marc/go/src/github.com/traefik/yaegi/cmd/yaegi/yaegi.go:144 +0x415
@mvertes mvertes added bug Something isn't working area/core labels Oct 22, 2020
@mvertes mvertes added this to the v0.9.x milestone Oct 22, 2020
@mvertes mvertes self-assigned this Oct 22, 2020
mvertes added a commit that referenced this issue Oct 22, 2020
Type checking on shift operands was failing for untyped variable values.

Fix propagation of type in assignment. Optimize assignment of arithmetic
operations on variables by skipping the assign and writing directly to
destination frame value in the operator function.

Skip some slow tests when given -short test option.

Fixes #917.
traefiker pushed a commit that referenced this issue Oct 23, 2020
Type checking on shift operands was failing for untyped variable values.

Fix propagation of type in assignment. Optimize assignment of arithmetic
operations on variables by skipping the assign and writing directly to
destination frame value in the operator function.

Skip some slow tests when given -short test option.

Fixes #917.
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