traefik / yaegi

Yaegi is Another Elegant Go Interpreter

Home Page:https://pkg.go.dev/github.com/traefik/yaegi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

panic when import `golang.org/x/text`

WLun001 opened this issue · comments

commented

The following program sample.go triggers a panic:

package main

import (
	"golang.org/x/text/language"
	"log"
)

func main() {
	log.Println(language.English)
}

Expected result:

$ go run ./sample.go

2021/06/19 21:42:46 en

Got: panic run: language: tag is not well-formed
Links to panic line number

$ yaegi ./sample.go


/Users/wlun/go/src/golang.org/x/text/internal/language/tags.go:12:3: panic
/Users/wlun/go/src/golang.org/x/text/internal/language/compact/compact.go:59:20: panic
run: language: tag is not well-formed
goroutine 1 [running]:
runtime/debug.Stack(0x1, 0xc0013c6800, 0x40)
	/usr/local/Cellar/go/1.16.3/libexec/src/runtime/debug/stack.go:24 +0x9f
github.com/traefik/yaegi/interp.(*Interpreter).eval.func1(0xc00223fc18)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/interp.go:503 +0xc8
panic(0x1b3a800, 0xc001a3dc20)
	/usr/local/Cellar/go/1.16.3/libexec/src/runtime/panic.go:965 +0x1b9
github.com/traefik/yaegi/interp.runCfg.func1(0xc001bccfd0, 0xc002052100, 0xc00223de68)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/run.go:185 +0x253
panic(0x1b3a800, 0xc001a3dc20)
	/usr/local/Cellar/go/1.16.3/libexec/src/runtime/panic.go:965 +0x1b9
github.com/traefik/yaegi/interp.runCfg.func1(0xc001bcd130, 0xc001295900, 0xc00223dc58)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/run.go:185 +0x253
panic(0x1b3a800, 0xc001a3dc20)
	/usr/local/Cellar/go/1.16.3/libexec/src/runtime/panic.go:965 +0x1b9
github.com/traefik/yaegi/interp._panic.func1(0xc001bcd130, 0xc0018fa550)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/run.go:838 +0x7f
github.com/traefik/yaegi/interp.runCfg(0xc001295900, 0xc001bcd130)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/run.go:191 +0x87
github.com/traefik/yaegi/interp.call.func7(0xc001bccfd0, 0xc0015b16c0)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/run.go:1272 +0xd05
github.com/traefik/yaegi/interp.runCfg(0xc002052100, 0xc001bccfd0)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/run.go:191 +0x87
github.com/traefik/yaegi/interp.(*Interpreter).run(0xc000366000, 0xc001ea5800, 0xc000368000)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/run.go:122 +0x2b0
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc000366000, 0x0, 0x0, 0xc001d0ac91, 0x2b, 0x1078e01, 0xc0004a6158, 0x8, 0x0, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/src.go:156 +0xad9
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc0014ffd00, 0xc00223ec48)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/gta.go:222 +0x12e5
github.com/traefik/yaegi/interp.(*node).Walk(0xc0014ffd00, 0xc00223ec48, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/interp.go:232 +0xb5
github.com/traefik/yaegi/interp.(*node).Walk(0xc0014fef00, 0xc00223ec48, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/interp.go:236 +0x66
github.com/traefik/yaegi/interp.(*node).Walk(0xc0014fe800, 0xc00223ec48, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/interp.go:236 +0x66
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc000366000, 0xc0014fe800, 0xc00011e580, 0x1a, 0xc000488041, 0x1a, 0xc001bbfc28, 0x8, 0xc0014fe800, 0x0, ...)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/gta.go:20 +0x21f
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc000366000, 0x0, 0x0, 0xc000488041, 0x1a, 0x1, 0x16, 0xc000211300, 0xca, 0xc000212510)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/src.go:100 +0xf57
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc000210400, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/gta.go:222 +0x12e5
github.com/traefik/yaegi/interp.(*node).Walk(0xc000210400, 0xc00223f9b8, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/interp.go:232 +0xb5
github.com/traefik/yaegi/interp.(*node).Walk(0xc000210300, 0xc00223f9b8, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/interp.go:236 +0x66
github.com/traefik/yaegi/interp.(*node).Walk(0xc000210100, 0xc00223f9b8, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/interp.go:236 +0x66
github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc000366000, 0xc000210100, 0xc00020d9d0, 0x4, 0xc00020d9d0, 0x4, 0x10, 0xc000200240, 0x0, 0xc0002063e0, ...)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/gta.go:20 +0x21f
github.com/traefik/yaegi/interp.(*Interpreter).gtaRetry(0xc000366000, 0xc00223fb88, 0x1, 0x1, 0xc00020d9d0, 0x4, 0xc00020d9d0, 0x4)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/gta.go:311 +0x12c
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc000366000, 0xc0002c6310, 0x6e, 0x7ffeefbffb2e, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/interp.go:525 +0x2a5
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0xc000366000, 0x7ffeefbffb2e, 0x9, 0xc0002c6200, 0x6e, 0x0, 0x0, 0xc0001b1cb0)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/interp/interp.go:417 +0x105
main.runFile(0xc000366000, 0x7ffeefbffb2e, 0x9, 0x0, 0x1, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/cmd/yaegi/run.go:139 +0xb1
main.run(0xc000032050, 0x1, 0x1, 0xc00000a501, 0xc000001680)
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/cmd/yaegi/run.go:102 +0x99d
main.main()
	/Users/wlun/go/pkg/mod/github.com/traefik/yaegi@v0.9.18/cmd/yaegi/yaegi.go:144 +0x415
commented

any ETA for this ? or any alternative can do for now? needed for a plugin

Sorry, I cannot provide ETAs.

commented

Sorry to ping, any updates on this?

commented

Tried with the latest release, it doesn't panic, but the output is not expected. Could you please help to check @nrwiersma

Expected

go run sample.go

2021/09/16 18:16:57 en

Actual output

yaegi ./sample.go


2021/09/16 18:16:59 {134 134 <nil>}

It is not possible for yaegi to have to output you want, as the struct generated for language.English does not actually have a String method (this is a limitation in Go reflect) and is therefore not a Stringer which is what this output is relying on.

commented

any suggestion or alternative that I can do from here? @nrwiersma

You have 3 option:

  1. Change Go, the issue is here: golang/go#16522
  2. Move golang.org/x/text/language from be interpreted to being native using yaegi Export and Use
  3. Change your code

But I cannot help you further than that.

commented

@nrwiersma thanks a lot