traefik / yaegi

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

gopkg.in/yaml.v3 issue #1519

Closed caius-kong closed 1 year ago

caius-kong commented 1 year ago

The following program sample.go triggers an unexpected result

package main

import (
    "fmt"
    "os"

    "gopkg.in/yaml.v3"
)

func main() {
    readYAML("sdz.yaml")
}

func readYAML(path string) {
    b, err := os.ReadFile(path)
    if err != nil {
        fmt.Printf("read yaml failed: %v\n", err)
    }

    var doc = make(map[interface{}]interface{})
    if err := yaml.Unmarshal(b, &doc); err != nil {
        fmt.Printf("unmarshal yaml failed: %v\n", err)
    }
}

Expected result

map[components:map[schemas:map.......

Got

/Users/caius_kong/go/src/gopkg.in/yaml.v3/readerc.go:79:2: panic
/Users/caius_kong/go/src/gopkg.in/yaml.v3/readerc.go:49:7: panic
/Users/caius_kong/go/src/gopkg.in/yaml.v3/readerc.go:114:5: panic
/Users/caius_kong/go/src/gopkg.in/yaml.v3/scannerc.go:689:5: panic
/Users/caius_kong/go/src/gopkg.in/yaml.v3/scannerc.go:664:6: panic
/Users/caius_kong/go/src/gopkg.in/yaml.v3/parserc.go:69:5: panic
/Users/caius_kong/go/src/gopkg.in/yaml.v3/parserc.go:232:11: panic
/Users/caius_kong/go/src/gopkg.in/yaml.v3/parserc.go:153:9: panic
/Users/caius_kong/go/src/gopkg.in/yaml.v3/parserc.go:121:2: panic
/Users/caius_kong/go/src/gopkg.in/yaml.v3/decode.go:81:5: panic
/Users/caius_kong/go/src/gopkg.in/yaml.v3/decode.go:63:5: panic
/Users/caius_kong/go/src/gopkg.in/yaml.v3/decode.go:148:2: panic
/Users/caius_kong/go/src/gopkg.in/yaml.v3/yaml.go:290:10: panic
/Users/caius_kong/go/src/gopkg.in/yaml.v3/yaml.go:89:9: panic
./sample.go:17:12: panic
./sample.go:13:2: panic
run: reflect: Call using *struct { Xerror int; Xproblem string; Xproblem_offset int; Xproblem_value int; Xproblem_mark struct { Xindex int; Xline int; Xcolumn int }; Xcontext string; Xcontext_mark struct { Xindex int; Xline int; Xcolumn int }; Xread_handler func(*unsafe2.dummy, []uint8) (int, error); Xinput_reader io.Reader; Xinput []uint8; Xinput_pos int; Xeof bool; Xbuffer []uint8; Xbuffer_pos int; Xunread int; Xnewlines int; Xraw_buffer []uint8; Xraw_buffer_pos int; Xencoding int; Xoffset int; Xmark struct { Xindex int; Xline int; Xcolumn int }; Xhead_comment []uint8; Xline_comment []uint8; Xfoot_comment []uint8; Xtail_comment []uint8; Xstem_comment []uint8; Xcomments []struct { Xscan_mark struct { Xindex int; Xline int; Xcolumn int }; Xtoken_mark struct { Xindex int; Xline int; Xcolumn int }; Xstart_mark struct { Xindex int; Xline int; Xcolumn int }; Xend_mark struct { Xindex int; Xline int; Xcolumn int }; Xhead []uint8; Xline []uint8; Xfoot []uint8 }; Xcomments_head int; Xstream_start_produced bool; Xstream_end_produced bool; Xflow_level int; Xtokens []struct { Xtyp int; Xstart_mark struct { Xindex int; Xline int; Xcolumn int }; Xend_mark struct { Xindex int; Xline int; Xcolumn int }; Xencoding int; Xvalue []uint8; Xsuffix []uint8; Xprefix []uint8; Xstyle int8; Xmajor int8; Xminor int8 }; Xtokens_head int; Xtokens_parsed int; Xtoken_available bool; Xindent int; Xindents []int; Xsimple_key_allowed bool; Xsimple_keys []struct { Xpossible bool; Xrequired bool; Xtoken_number int; Xmark struct { Xindex int; Xline int; Xcolumn int } }; Xsimple_keys_by_tok map[int]int; Xstate int; Xstates []int; Xmarks []struct { Xindex int; Xline int; Xcolumn int }; Xtag_directives []struct { Xhandle []uint8; Xprefix []uint8 }; Xaliases []struct { Xanchor []uint8; Xindex int; Xmark struct { Xindex int; Xline int; Xcolumn int } }; Xdocument *struct { Xnodes []struct { Xtyp int; Xtag []uint8; Xscalar struct { Xvalue []uint8; Xlength int; Xstyle int8 }; Xsequence struct { Xitems_data []int; Xstyle int8 }; Xmapping struct { Xpairs_data []struct { Xkey int; Xvalue int }; Xpairs_start *struct { Xkey int; Xvalue int }; Xpairs_end *struct { Xkey int; Xvalue int }; Xpairs_top *struct { Xkey int; Xvalue int }; Xstyle int8 }; Xstart_mark struct { Xindex int; Xline int; Xcolumn int }; Xend_mark struct { Xindex int; Xline int; Xcolumn int } }; Xversion_directive *struct { Xmajor int8; Xminor int8 }; Xtag_directives_data []struct { Xhandle []uint8; Xprefix []uint8 }; Xtag_directives_start int; Xtag_directives_end int; Xstart_implicit int; Xend_implicit int; Xstart_mark struct { Xindex int; Xline int; Xcolumn int }; Xend_mark struct { Xindex int; Xline int; Xcolumn int } } } as type *unsafe2.dummy
goroutine 1 [running]:
runtime/debug.Stack()
        runtime/debug/stack.go:24 +0x64
github.com/traefik/yaegi/interp.(*Interpreter).Execute.func1()
        github.com/traefik/yaegi/interp/program.go:146 +0x74
panic({0x1016e8200, 0x14000704270})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1016e8200, 0x14000704270})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1016e8200, 0x14000704270})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1016e8200, 0x14000704270})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1016e8200, 0x14000704270})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp._panic.func1(0x1400104eb00?)
        github.com/traefik/yaegi/interp/run.go:901 +0x50
github.com/traefik/yaegi/interp.runCfg(0x1400133ec80, 0x1400104eb00, 0x3300000000000000?, 0x1015a91a0?)
        github.com/traefik/yaegi/interp/run.go:213 +0x21c
github.com/traefik/yaegi/interp.genFunctionWrapper.func1.1({0x14000704258, 0x1, 0x1?})
        github.com/traefik/yaegi/interp/run.go:1015 +0x3d8
reflect.Value.call({0x14001712c60?, 0x140016ad050?, 0x100c07830?}, {0x101379725, 0x4}, {0x140016acfa8, 0x1, 0x0?})
        reflect/value.go:584 +0x688
reflect.Value.Call({0x14001712c60?, 0x140016ad050?, 0x140025567c8?}, {0x140016acfa8?, 0x140025567c8?, 0x100c255c8?})
        reflect/value.go:368 +0x90
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:190 +0x230
panic({0x1015c4b40, 0x1400058e6d0})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1015c4b40, 0x1400058e6d0})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1015c4b40, 0x1400058e6d0})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1015c4b40, 0x1400058e6d0})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1015c4b40, 0x1400058e6d0})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1015c4b40, 0x1400058e6d0})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1015c4b40, 0x1400058e6d0})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1015c4b40, 0x1400058e6d0})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1015c4b40, 0x1400058e6d0})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1015c4b40, 0x1400058e6d0})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1015c4b40, 0x1400058e6d0})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1015c4b40, 0x1400058e6d0})
        runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:205 +0x11c
panic({0x1015c4b40, 0x1400058e6d0})
        runtime/panic.go:884 +0x204
reflect.Value.call({0x14000114240?, 0x14001c6b068?, 0x140002be538?}, {0x101379725, 0x4}, {0x140016ad6b0, 0x2, 0x140008a0e40?})
        reflect/value.go:440 +0x1478
reflect.Value.Call({0x14000114240?, 0x14001c6b068?, 0x30?}, {0x140016ad6b0?, 0x140002be501?, 0x1400104e8f0?})
        reflect/value.go:368 +0x90
github.com/traefik/yaegi/interp.callBin.func2({0x14000114240?, 0x14001c6b068?, 0x182?}, {0x140016ad6b0?, 0x140002be628?, 0x100e61e5c?})
        github.com/traefik/yaegi/interp/run.go:1506 +0x28
github.com/traefik/yaegi/interp.callBin.func9(0x1400104e8f0?)
        github.com/traefik/yaegi/interp/run.go:1650 +0x140
github.com/traefik/yaegi/interp.runCfg(0x14000e91540, 0x1400104e8f0, 0x140015ea725?, 0x14001612380?)
        github.com/traefik/yaegi/interp/run.go:213 +0x21c
github.com/traefik/yaegi/interp.call.func9(0x1400104e840)
        github.com/traefik/yaegi/interp/run.go:1442 +0x798
github.com/traefik/yaegi/interp.runCfg(0x14000e82780, 0x1400104e840, 0x140002be9b8?, 0x14001612380?)
        github.com/traefik/yaegi/interp/run.go:213 +0x21c
github.com/traefik/yaegi/interp.call.func9(0x1400104e790)
        github.com/traefik/yaegi/interp/run.go:1442 +0x798
github.com/traefik/yaegi/interp.runCfg(0x14000ea12c0, 0x1400104e790, 0x101ef45b8?, 0x1015c3cc0?)
        github.com/traefik/yaegi/interp/run.go:213 +0x21c
github.com/traefik/yaegi/interp.call.func9(0x1400104e6e0)
        github.com/traefik/yaegi/interp/run.go:1442 +0x798
github.com/traefik/yaegi/interp.runCfg(0x14000854000, 0x1400104e6e0, 0x101c06a20?, 0x14001612380?)
        github.com/traefik/yaegi/interp/run.go:213 +0x21c
github.com/traefik/yaegi/interp.call.func9(0x1400104e630)
        github.com/traefik/yaegi/interp/run.go:1442 +0x798
github.com/traefik/yaegi/interp.runCfg(0x1400069b680, 0x1400104e630, 0x10137b3d7?, 0x14001612380?)
        github.com/traefik/yaegi/interp/run.go:213 +0x21c
github.com/traefik/yaegi/interp.call.func9(0x1400104e580)
        github.com/traefik/yaegi/interp/run.go:1442 +0x798
github.com/traefik/yaegi/interp.runCfg(0x14000cc6a00, 0x1400104e580, 0x0?, 0x14001612380?)
        github.com/traefik/yaegi/interp/run.go:213 +0x21c
github.com/traefik/yaegi/interp.call.func9(0x1400104e4d0)
        github.com/traefik/yaegi/interp/run.go:1442 +0x798
github.com/traefik/yaegi/interp.runCfg(0x14000cfc280, 0x1400104e4d0, 0x140002bf778?, 0x14001612a80?)
        github.com/traefik/yaegi/interp/run.go:213 +0x21c

Yaegi Version

0.15.0

Additional Notes

if traefik 2.6.3, this ok

caiuskong commented 1 year ago

@mvertes Just merge to master, not published yet... Hope to integrate into the latest traefik as soon as possible.

caiuskong commented 1 year ago

hi @mvertes , I have seen that yaegi v0.15.1 has already fixed the issue, but traefik (go.mod) currently only updates the yaegi version to v0.15.0. Can it be updated to v0.15.1 as soon as possible?