yaegi
yaegi copied to clipboard
Cannot import google.golang.org/grpc
The following program sample.go
triggers an unexpected result
package main
import (
"fmt"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
func main() {
fmt.Println("Hello")
conn, err := grpc.Dial("localhost:5000", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
fmt.Println("did not connect: %v", err)
}
defer conn.Close()
fmt.Println("Finished.")
}
Expected result
Hello
Finished.
Got
panic: runtime error: index out of range [1] with length 0 [recovered]
panic: C:\Users\Andreas\go\src\google.golang.org\protobuf\reflect\protoreflect\value_union.go:192:9: CFG post-order panic: runtime error: index out of range [1] with length 0
goroutine 1 [running]:
github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2.1()
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/cfg.go:536 +0x78
panic({0x15ff020, 0xc00186dba8})
C:/Program Files/Go/src/runtime/panic.go:890 +0x262
github.com/traefik/yaegi/interp.(*itype).fieldSeq(0xc0011c6180?, {0xc0011c6180?, 0x1?, 0xc0010f8d80?})
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/type.go:1602 +0x5e
github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2(0xc0010f9d40)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/cfg.go:1785 +0x546c
github.com/traefik/yaegi/interp.(*node).Walk(0xc0010f9d40, 0xc000e98158, 0xc000e981a0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:291 +0xad
github.com/traefik/yaegi/interp.(*node).Walk(0xc0010f9c20, 0xc000e98158, 0xc000e981a0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc0010f9b00, 0xc000e98158, 0xc000e981a0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc0010f99e0, 0xc000e98158, 0xc000e981a0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc0010f8b40, 0xc000e98158, 0xc000e981a0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc000c3b680, 0xc000e98158, 0xc000e981a0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*Interpreter).cfg(0xc000374000, 0xc000c3b680, 0xc000e6b0e0, {0xc000644ac1, 0x2f}, {0xc000c42200, 0xc})
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/cfg.go:62 +0x2b4
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc000374000, {0xc000644d80, 0x37}, {0xc000644ac1, 0x2f}, 0x1)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/src.go:125 +0x6d5
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc000a79680)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:261 +0x2135
github.com/traefik/yaegi/interp.(*node).Walk(0xc000a79680, 0xc000e98ed0, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:284 +0x34
github.com/traefik/yaegi/interp.(*node).Walk(0xc000a78ea0, 0xc000e98ed0, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc000a78c60, 0xc000e98ed0, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc000374000, 0xc000a78c60, {0xc000644d80, 0x37}, {0xc000953f41, 0x37}, {0xc0007f61f0, 0xa})
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:20 +0x22b
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc000374000, {0xc0002039b0, 0x2d}, {0xc000953f41, 0x37}, 0x1)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/src.go:108 +0x100f
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc0007df680)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:261 +0x2135
github.com/traefik/yaegi/interp.(*node).Walk(0xc0007df680, 0xc000e99c18, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:284 +0x34
github.com/traefik/yaegi/interp.(*node).Walk(0xc0007df0e0, 0xc000e99c18, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc0007deea0, 0xc000e99c18, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc000374000, 0xc0007deea0, {0xc0002039b0, 0x2d}, {0xc000202d51, 0x2d}, {0xc00063cd40, 0x9})
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:20 +0x22b
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc000374000, {0xc00009c700, 0x20}, {0xc000202d51, 0x2d}, 0x1)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/src.go:108 +0x100f
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc0005666c0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:261 +0x2135
github.com/traefik/yaegi/interp.(*node).Walk(0xc0005666c0, 0xc000e9a960, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:284 +0x34
github.com/traefik/yaegi/interp.(*node).Walk(0xc000566120, 0xc000e9a960, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc000559e60, 0xc000e9a960, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc000374000, 0xc000559e60, {0xc00009c700, 0x20}, {0xc000202511, 0x20}, {0xc000038f90, 0x5})
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:20 +0x22b
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc000374000, {0xc000202ab0, 0x22}, {0xc000202511, 0x20}, 0x1)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/src.go:108 +0x100f
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc0004ea5a0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:261 +0x2135
github.com/traefik/yaegi/interp.(*node).Walk(0xc0004ea5a0, 0xc000e9b6a8, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:284 +0x34
github.com/traefik/yaegi/interp.(*node).Walk(0xc0004cbb00, 0xc000e9b6a8, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc0004cb8c0, 0xc000e9b6a8, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc000374000, 0xc0004cb8c0, {0xc000202ab0, 0x22}, {0xc000202ba1, 0x22}, {0xc0004c5fa0, 0xb})
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:20 +0x22b
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc000374000, {0xc000203110, 0x28}, {0xc000202ba1, 0x22}, 0x1)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/src.go:108 +0x100f
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc000861560)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:261 +0x2135
github.com/traefik/yaegi/interp.(*node).Walk(0xc000861560, 0xc000e9c3f0, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:284 +0x34
github.com/traefik/yaegi/interp.(*node).Walk(0xc000860900, 0xc000e9c3f0, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc0008606c0, 0xc000e9c3f0, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc000374000, 0xc0008606c0, {0xc000203110, 0x28}, {0xc000202751, 0x28}, {0xc000096a48, 0x8})
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:20 +0x22b
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc000374000, {0xc00009c480, 0x1f}, {0xc000202751, 0x28}, 0x1)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/src.go:108 +0x100f
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc0001ea000)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:261 +0x2135
github.com/traefik/yaegi/interp.(*node).Walk(0xc0001ea000, 0xc000e9d138, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:284 +0x34
github.com/traefik/yaegi/interp.(*node).Walk(0xc0001e1e60, 0xc000e9d138, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc0001e1c20, 0xc000e9d138, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc000374000, 0xc0001e1c20, {0xc00009c480, 0x1f}, {0xc0002021b1, 0x1f}, {0xc000096940, 0x8})
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:20 +0x22b
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc000374000, {0xc00009c320, 0x1f}, {0xc0002021b1, 0x1f}, 0x1)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/src.go:108 +0x100f
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc0001be240)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:261 +0x2135
github.com/traefik/yaegi/interp.(*node).Walk(0xc0001be240, 0xc000e9de80, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:284 +0x34
github.com/traefik/yaegi/interp.(*node).Walk(0xc0001a1560, 0xc000e9de80, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc0001a1320, 0xc000e9de80, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc000374000, 0xc0001a1320, {0xc00009c320, 0x1f}, {0xc00028fb91, 0x1f}, {0xc0000960e0, 0x8})
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:20 +0x22b
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc000374000, {0xc000098030, 0x16}, {0xc00028fb91, 0x1f}, 0x1)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/src.go:108 +0x100f
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc0004ec5a0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:261 +0x2135
github.com/traefik/yaegi/interp.(*node).Walk(0xc0004ec5a0, 0xc000e9ebc8, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:284 +0x34
github.com/traefik/yaegi/interp.(*node).Walk(0xc0004a5d40, 0xc000e9ebc8, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc0004a5b00, 0xc000e9ebc8, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc000374000, 0xc0004a5b00, {0xc000098030, 0x16}, {0xc0002901b1, 0x16}, {0xc000283348, 0x4})
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:20 +0x22b
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc000374000, {0xc000282db0, 0x4}, {0xc0002901b1, 0x16}, 0x1)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/src.go:108 +0x100f
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc000380fc0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:261 +0x2135
github.com/traefik/yaegi/interp.(*node).Walk(0xc000380fc0, 0xc000e9f910, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:284 +0x34
github.com/traefik/yaegi/interp.(*node).Walk(0xc000380c60, 0xc000e9f910, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc000380a20, 0xc000e9f910, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc000374000, 0xc000380a20, {0xc000282db0, 0x4}, {0xc000282db0, 0x4}, {0xc000282db0, 0x4})
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:20 +0x22b
github.com/traefik/yaegi/interp.(*Interpreter).gtaRetry(0xc000374000?, {0xc000119af0?, 0xc000304180?, 0xc000119a38?}, {0xc000282db0, 0x4}, {0xc000282db0, 0x4})
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:383 +0x154
github.com/traefik/yaegi/interp.(*Interpreter).CompileAST(0xc000374000, {0x1837f48?, 0xc000304180?})
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/program.go:87 +0x17f
github.com/traefik/yaegi/interp.(*Interpreter).compileSrc(0xc000374000, {0xc000372480?, 0x0?}, {0xc0000380c0?, 0xc000372480?}, 0x7d?)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/program.go:59 +0xb8
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc000374000, {0xc000372480?, 0x17d?}, {0xc0000380c0?, 0xc000372180?}, 0x7d?)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:552 +0x28
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0xc000374000, {0xc0000380c0, 0xb})
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:510 +0xab
main.runFile(0xc0000380c0?, {0xc0000380c0, 0xb}, 0x0)
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/cmd/yaegi/run.go:153 +0xee
main.run({0xc00006c050?, 0x2, 0x3})
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/cmd/yaegi/run.go:116 +0xbec
main.main()
C:/Users/Andreas/go/pkg/mod/github.com/traefik/[email protected]/cmd/yaegi/yaegi.go:144 +0x2cb
Yaegi Version
0.14.2
Additional Notes
I call yaegi with the switch "--unsafe" (yaegi --unsafe ./sample.go)
hi @mvertes , any updates on this sisue? I hit the same issue with protobuf
panic: /Users/xiaofan/code/plugin/src/github.com/xiaofan/milvus-cloud-plugin/vendor/google.golang.org/protobuf/reflect/protoreflect/value_union.go:191:9: CFG post-order panic: runtime error: index out of range [1] with length 0
I'm on it.
First, it is necessary to add the a comment line // yaegi:tags purego
at the start of the script, to skip dependencies in assembly, cgo, unsafe etc, mainly in protobuf (as far as I saw).
// yaegi:tags purego
package main
import (
[...]
Then there seems to be an issue related to interfaces that I think I can solve quickly. After that I see that grpc seems to rely extensively on reflect
and that may cause some interferences with yaegi, but I'm not here yet.
Same here with
package something
import (
github.com/pascaldekloe/redis
)
I'm on it.
First, it is necessary to add the a comment line
// yaegi:tags purego
at the start of the script, to skip dependencies in assembly, cgo, unsafe etc, mainly in protobuf (as far as I saw).// yaegi:tags purego package main import ( [...]
Then there seems to be an issue related to interfaces that I think I can solve quickly. After that I see that grpc seems to rely extensively on
reflect
and that may cause some interferences with yaegi, but I'm not here yet.
Will keep following the updates since yaegi is still the best we can find to compile some plugins