traefik / yaegi

Yaegi is Another Elegant Go Interpreter
https://pkg.go.dev/github.com/traefik/yaegi
Apache License 2.0
6.82k stars 342 forks source link

go:embed not work #1557

Closed laushunyu closed 1 year ago

laushunyu commented 1 year ago

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?😇