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

constant bit operation #907

Closed
mvertes opened this issue Oct 15, 2020 · 3 comments · Fixed by #908
Closed

constant bit operation #907

mvertes opened this issue Oct 15, 2020 · 3 comments · Fixed by #908
Labels
area/core bug Something isn't working
Milestone

Comments

@mvertes
Copy link
Member

mvertes commented Oct 15, 2020

The following program sample.go triggers a panic:

package main

import "fmt" 

const maxLen = int64(int(^uint(0) >> 1))
    
func main() {
    fmt.Println(maxLen)
}

Expected result:

$ go run ./sample.go
9223372036854775807

Got:

$ yaegi ./sample.go
run: ./sample.go:5:26: CFG post-order panic: reflect: call of reflect.Value.Int on uint Value
goroutine 1 [running]:
runtime/debug.Stack(0x1, 0xc000186a00, 0x40)
        /usr/lib/go/src/runtime/debug/stack.go:24 +0x9f
github.com/traefik/yaegi/interp.(*Interpreter).eval.func1(0xc000219c70)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:455 +0xc5
panic(0xeaa380, 0xc000129ee0)
        /usr/lib/go/src/runtime/panic.go:969 +0x175
github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2.1(0xc000151400)
        /home/marc/go/src/github.com/traefik/yaegi/interp/cfg.go:424 +0xb3
panic(0xe00a60, 0xc000129ea0)
        /usr/lib/go/src/runtime/panic.go:969 +0x175
reflect.Value.Int(...)
        /usr/lib/go/src/reflect/value.go:998
github.com/traefik/yaegi/interp.bitNotConst(0xc000151400)
        /home/marc/go/src/github.com/traefik/yaegi/interp/op.go:1970 +0x55f
github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2(0xc000151400)
        /home/marc/go/src/github.com/traefik/yaegi/interp/cfg.go:1751 +0x1632
github.com/traefik/yaegi/interp.(*node).Walk(0xc000151400, 0xc000219170, 0xc000219140)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:220 +0xa5
github.com/traefik/yaegi/interp.(*node).Walk(0xc000151300, 0xc000219170, 0xc000219140)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:217 +0x66
github.com/traefik/yaegi/interp.(*node).Walk(0xc000151100, 0xc000219170, 0xc000219140)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:217 +0x66
github.com/traefik/yaegi/interp.(*node).Walk(0xc000150f00, 0xc000219170, 0xc000219140)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:217 +0x66
github.com/traefik/yaegi/interp.(*node).Walk(0xc000150d00, 0xc000219170, 0xc000219140)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:217 +0x66
github.com/traefik/yaegi/interp.(*node).Walk(0xc000150c00, 0xc000219170, 0xc000219140)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:217 +0x66
github.com/traefik/yaegi/interp.(*Interpreter).cfg(0xc0003ae000, 0xc000150c00, 0xc00037c7f0, 0x4, 0x1, 0x0, 0xf, 0xc000151f00, 0x7f02b82feea8)
        /home/marc/go/src/github.com/traefik/yaegi/interp/cfg.go:63 +0x20f
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc000150c00, 0xc000219a20)
        /home/marc/go/src/github.com/traefik/yaegi/interp/gta.go:28 +0xb6c
github.com/traefik/yaegi/interp.(*node).Walk(0xc000150c00, 0xc000219a20, 0x0)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:213 +0xb5
github.com/traefik/yaegi/interp.(*node).Walk(0xc000150700, 0xc000219a20, 0x0)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:217 +0x66
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc0003ae000, 0xc000150700, 0xc00037c7f0, 0x4, 0xc00037c7f0, 0x4, 0xc0001c0540, 0x0, 0xc000219af8, 0xc0003ae040, ...)
        /home/marc/go/src/github.com/traefik/yaegi/interp/gta.go:20 +0x1f8
github.com/traefik/yaegi/interp.(*Interpreter).gtaRetry(0xc0003ae000, 0xc000219bd8, 0x1, 0x1, 0xc00037c7f0, 0x4, 0xc00037c7f0, 0x4)
        /home/marc/go/src/github.com/traefik/yaegi/interp/gta.go:304 +0x12c
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc0003ae000, 0xc0001c0540, 0x6b, 0x7ffcf99c94bd, 0x19, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:477 +0x295
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0xc0003ae000, 0x7ffcf99c94bd, 0x19, 0xc0001c0400, 0x6b, 0x0, 0x0, 0xc0003f4410)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:394 +0xfa
main.runFile(0xc0003ae000, 0x7ffcf99c94bd, 0x19, 0xc000138e40, 0x0)
        /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 area/core bug Something isn't working labels Oct 15, 2020
@mvertes mvertes added this to the v0.9.x milestone Oct 15, 2020
@tolgaerdonmez
Copy link

I just tried it on my device, it seems to work just fine., which version of go are you trying, and which type of system are you running ?

I'm using go version go1.15.1 darwin/amd64

@mvertes
Copy link
Member Author

mvertes commented Oct 15, 2020

yaegi v0.9.3, go1.15.2 linux/amd64

@tolgaerdonmez
Copy link

Oh, I forgot to check with yaegi, also not working.

mvertes added a commit that referenced this issue Oct 15, 2020
In unary constant operations, the test for unsigned was defeated by
testing for int first, which is true also for unsigned. Make sure that
testing for unsigned precedes testing for int.

Fixes #907.
traefiker pushed a commit that referenced this issue Oct 19, 2020
In unary constant operations, the test for unsigned was defeated by
testing for int first, which is true also for unsigned. Make sure that
testing for unsigned precedes testing for int.

Fixes #907.
traefiker pushed a commit that referenced this issue Oct 19, 2020
In unary constant operations, the test for unsigned was defeated by
testing for int first, which is true also for unsigned. Make sure that
testing for unsigned precedes testing for int.

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

2 participants