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

go:embed not work #1557

Closed
laushunyu opened this issue Jun 14, 2023 · 0 comments · Fixed by #1559
Closed

go:embed not work #1557

laushunyu opened this issue Jun 14, 2023 · 0 comments · Fixed by #1559
Labels
area/stdlib bug Something isn't working

Comments

@laushunyu
Copy link
Contributor

The following program sample.go triggers an unexpected result

package main

import (
	"fmt"
	"github.com/traefik/yaegi/interp"
	"github.com/traefik/yaegi/stdlib"
)

func main() {
	interpreter := interp.New(interp.Options{})
	interpreter.Use(stdlib.Symbols)

	_, err := interpreter.Compile(`package main

import (
	_ "embed"
)

//go:embed symbol.go
var raw []byte

func SelfSrc() []byte {
	return raw
}`)
	if err != nil {
		panic(err)
	}

	mainSymbols := interpreter.Symbols("main")["main"]
	SelfSrc := mainSymbols["SelfSrc"].Interface().(func() []byte)
	fmt.Printf("src code: %s", SelfSrc())
}

Expected result

# go run .
src code: 
<src code of sample.go>

Got

# go run .
src code:

Yaegi Version

v0.15.1

Additional Notes

hi,
I found embed.FS symbol in stdlib, but //go:embed not work, is it expected?😇

@mvertes mvertes added bug Something isn't working area/stdlib labels Jun 14, 2023
traefiker pushed a commit that referenced this issue Jun 14, 2023
Embedding files using `//go:embed` and `embed` packages can not be supported in yaegi, so it is better to not generate the wrapper to embed and have a graceful error in case of usage of `embed.FS` in the interpreter.
Also update README about unsuported directives.

Fixes #1557.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/stdlib bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants