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

Problem with go-chi/chi #1419

Closed
RussellLuo opened this issue Jun 23, 2022 · 2 comments
Closed

Problem with go-chi/chi #1419

RussellLuo opened this issue Jun 23, 2022 · 2 comments
Labels
area/core bug Something isn't working

Comments

@RussellLuo
Copy link
Contributor

RussellLuo commented Jun 23, 2022

The following program sample.go triggers an unexpected result

package main
  
import "github.com/go-chi/chi"

func main() {
	router := chi.NewRouter()
	println("router:", router)
}

Expected result

$ go run ./sample.go
router: 0xc000129e80

Got

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

goroutine 1 [running]:
reflect.Value.Int(...)
	/usr/local/go/src/reflect/value.go:1413
github.com/traefik/yaegi/interp.nodeType2(0xc000171b00, 0xc00016c990, 0xc00070cb40, {0xc0004d3b40, 0x4, 0x8})
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/type.go:433 +0x44de
github.com/traefik/yaegi/interp.nodeType2(0xc000171b00, 0xc00016c990, 0xc0005a4b40, {0xc000525c60, 0x3, 0x4})
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/type.go:902 +0x4abe
github.com/traefik/yaegi/interp.nodeType2(0xc000171b00, 0xc00016c990, 0xc000713200, {0xc000525c60, 0x2, 0x4})
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/type.go:715 +0x550e
github.com/traefik/yaegi/interp.nodeType2(0xc000171b00, 0xc00016c990, 0xc0007130e0, {0xc000502f90, 0x1, 0x2})
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/type.go:403 +0x129f
github.com/traefik/yaegi/interp.nodeType2(0xc000171b00, 0xc00016c990, 0xc000712000, {0xc0000ab560, 0x0, 0x1})
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/type.go:681 +0x3acd
github.com/traefik/yaegi/interp.nodeType(...)
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/type.go:378
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc0007117a0)
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/gta.go:144 +0x385
github.com/traefik/yaegi/interp.(*node).Walk(0xc0007117a0, 0xc00056eb70, 0x0)
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/interp.go:288 +0x34
github.com/traefik/yaegi/interp.(*node).Walk(0xc000348b40, 0xc00056eb70, 0x0)
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/interp.go:292 +0x75
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc000171b00, 0xc000348b40, {0xc000038240, 0x15}, {0xc0000381f9, 0x15}, {0xc000360c30, 0x3})
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/gta.go:20 +0x22b
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc000171b00, {0xc000360ac0, 0x4}, {0xc0000381f9, 0x15}, 0x1)
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/src.go:108 +0x100a
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc0003ce5a0)
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/gta.go:248 +0x1e95
github.com/traefik/yaegi/interp.(*node).Walk(0xc0003ce5a0, 0xc00056f910, 0x0)
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/interp.go:288 +0x34
github.com/traefik/yaegi/interp.(*node).Walk(0xc0003ce480, 0xc00056f910, 0x0)
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/interp.go:292 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc0003ce240, 0xc00056f910, 0x0)
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/interp.go:292 +0x75
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc000171b00, 0xc0003ce240, {0xc000360ac0, 0x4}, {0xc000360ac0, 0x4}, {0xc000360ac0, 0x4})
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/gta.go:20 +0x22b
github.com/traefik/yaegi/interp.(*Interpreter).gtaRetry(0xc000171b00?, {0xc0001b7af0?, 0xc00013c880?, 0xc0001b7a38?}, {0xc000360ac0, 0x4}, {0xc000360ac0, 0x4})
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/gta.go:361 +0x155
github.com/traefik/yaegi/interp.(*Interpreter).CompileAST(0xc000171b00, {0x1c1f078?, 0xc00013c880?})
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/program.go:87 +0x17f
github.com/traefik/yaegi/interp.(*Interpreter).compileSrc(0xc000171b00, {0xc0002e1400?, 0x0?}, {0x7ffeefbff9c6?, 0xc0002e1400?}, 0x75?)
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/program.go:59 +0xb8
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc000171b00, {0xc0002e1400?, 0x75?}, {0x7ffeefbff9c6?, 0xc0002e1300?}, 0x75?)
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/interp.go:610 +0x28
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0xc000171b00, {0x7ffeefbff9c6, 0x7})
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/interp/interp.go:512 +0xab
main.runFile(0x7ffeefbff9c6?, {0x7ffeefbff9c6, 0x7}, 0x0)
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/cmd/yaegi/run.go:153 +0xee
main.run({0xc000032050?, 0x1, 0x1})
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/cmd/yaegi/run.go:116 +0xbec
main.main()
	/Users/russellluo/Labs/learn_go/projects/src/github.com/traefik/yaegi/cmd/yaegi/yaegi.go:144 +0x2dc

Yaegi Version

v0.13.0

Additional Notes

No response

@RussellLuo
Copy link
Contributor Author

Per the current implementation:

yaegi/interp/type.go

Lines 427 to 434 in f76db27

case v.IsValid():
// Size if defined by a constant litteral value.
if isConstantValue(v.Type()) {
c := v.Interface().(constant.Value)
length = constToInt(c)
} else {
length = int(v.Int())
}

I guess this might be a possible fix:

case v.IsValid(): 
	// Size if defined by a constant litteral value. 
-	if isConstantValue(v.Type()) { 
-		c := v.Interface().(constant.Value) 
-		length = constToInt(c) 
-	} else { 
-		length = int(v.Int()) 
-	}
+	length = int(vInt(v))

@mvertes mvertes added bug Something isn't working area/core labels Jun 23, 2022
@mvertes mvertes added this to the v0.13.x milestone Jun 23, 2022
@ldez ldez modified the milestones: v0.13.x, v0.14.x Aug 3, 2022
@mvertes
Copy link
Member

mvertes commented Mar 22, 2023

sample.go works with yaegi v0.15.0

@mvertes mvertes closed this as completed Mar 22, 2023
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

No branches or pull requests

3 participants