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

panic when import golang.org/x/text #1158

Closed
WLun001 opened this issue Jun 19, 2021 · 8 comments · Fixed by #1248
Closed

panic when import golang.org/x/text #1158

WLun001 opened this issue Jun 19, 2021 · 8 comments · Fixed by #1248
Labels
area/core bug Something isn't working
Milestone

Comments

@WLun001
Copy link

WLun001 commented Jun 19, 2021

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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/interp/run.go:838 +0x7f
github.com/traefik/yaegi/interp.runCfg(0xc001295900, 0xc001bcd130)
	/Users/wlun/go/pkg/mod/github.com/traefik/[email protected]/interp/run.go:191 +0x87
github.com/traefik/yaegi/interp.call.func7(0xc001bccfd0, 0xc0015b16c0)
	/Users/wlun/go/pkg/mod/github.com/traefik/[email protected]/interp/run.go:1272 +0xd05
github.com/traefik/yaegi/interp.runCfg(0xc002052100, 0xc001bccfd0)
	/Users/wlun/go/pkg/mod/github.com/traefik/[email protected]/interp/run.go:191 +0x87
github.com/traefik/yaegi/interp.(*Interpreter).run(0xc000366000, 0xc001ea5800, 0xc000368000)
	/Users/wlun/go/pkg/mod/github.com/traefik/[email protected]/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/[email protected]/interp/src.go:156 +0xad9
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc0014ffd00, 0xc00223ec48)
	/Users/wlun/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:222 +0x12e5
github.com/traefik/yaegi/interp.(*node).Walk(0xc0014ffd00, 0xc00223ec48, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:232 +0xb5
github.com/traefik/yaegi/interp.(*node).Walk(0xc0014fef00, 0xc00223ec48, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:236 +0x66
github.com/traefik/yaegi/interp.(*node).Walk(0xc0014fe800, 0xc00223ec48, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/[email protected]/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/[email protected]/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/[email protected]/interp/src.go:100 +0xf57
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc000210400, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/[email protected]/interp/gta.go:222 +0x12e5
github.com/traefik/yaegi/interp.(*node).Walk(0xc000210400, 0xc00223f9b8, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:232 +0xb5
github.com/traefik/yaegi/interp.(*node).Walk(0xc000210300, 0xc00223f9b8, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/[email protected]/interp/interp.go:236 +0x66
github.com/traefik/yaegi/interp.(*node).Walk(0xc000210100, 0xc00223f9b8, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/interp/interp.go:417 +0x105
main.runFile(0xc000366000, 0x7ffeefbffb2e, 0x9, 0x0, 0x1, 0x0)
	/Users/wlun/go/pkg/mod/github.com/traefik/[email protected]/cmd/yaegi/run.go:139 +0xb1
main.run(0xc000032050, 0x1, 0x1, 0xc00000a501, 0xc000001680)
	/Users/wlun/go/pkg/mod/github.com/traefik/[email protected]/cmd/yaegi/run.go:102 +0x99d
main.main()
	/Users/wlun/go/pkg/mod/github.com/traefik/[email protected]/cmd/yaegi/yaegi.go:144 +0x415
@WLun001 WLun001 changed the title language: tag is not well-formed panic when import golang.org/x/text Jun 19, 2021
@WLun001 WLun001 changed the title panic when import golang.org/x/text panic when import golang.org/x/text Jun 19, 2021
@mvertes mvertes added area/core bug Something isn't working labels Jun 21, 2021
@WLun001
Copy link
Author

WLun001 commented Jun 22, 2021

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

@mvertes
Copy link
Member

mvertes commented Jun 22, 2021

Sorry, I cannot provide ETAs.

@WLun001
Copy link
Author

WLun001 commented Aug 9, 2021

Sorry to ping, any updates on this?

traefiker pushed a commit that referenced this issue Sep 6, 2021
When a const is late binding and specified with a type, the GTA defineStmt was creating the symbol with the current scopes `iota` which is incorrect. The symbol should be created with the source nodes `rval`.

Related to #1158
traefiker pushed a commit that referenced this issue Sep 6, 2021
When `nodeType` recovers names and methods, it can overwrite the data if the type is an aliasT. When aliasing a type, do not recover the methods, this will be done in the GTA typeSpec pass.

Related to #1158
Bai-Yingjie pushed a commit to godevsig/yaegi that referenced this issue Sep 12, 2021
When a const is late binding and specified with a type, the GTA defineStmt was creating the symbol with the current scopes `iota` which is incorrect. The symbol should be created with the source nodes `rval`.

Related to traefik#1158
Bai-Yingjie pushed a commit to godevsig/yaegi that referenced this issue Sep 12, 2021
When `nodeType` recovers names and methods, it can overwrite the data if the type is an aliasT. When aliasing a type, do not recover the methods, this will be done in the GTA typeSpec pass.

Related to traefik#1158
@mvertes mvertes added this to the v0.10.x milestone Sep 15, 2021
traefiker pushed a commit that referenced this issue Sep 15, 2021
The current `nodeType` selector precedence is heavy handed in favour of package type. It seems to often create `typeSym` symbols as variable types in the scope will never be found. To fix this if the ancestor node is a field expression, the package type is searched for. After this, if the type is still `nil` the normal scope is searched using `nodeType2`.

Fixes #1158
@WLun001
Copy link
Author

WLun001 commented Sep 16, 2021

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>}

@nrwiersma
Copy link
Contributor

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.

@WLun001
Copy link
Author

WLun001 commented Sep 17, 2021

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

@nrwiersma
Copy link
Contributor

You have 3 option:

  1. Change Go, the issue is here: reflect: NamedOf 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.

@WLun001
Copy link
Author

WLun001 commented Sep 17, 2021

@nrwiersma thanks a lot

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.

3 participants