yaegi icon indicating copy to clipboard operation
yaegi copied to clipboard

returned const is not converted to defined type

Open mvertes opened this issue 1 year ago • 0 comments

The following program sample.go triggers an unexpected result

package main

type T uint16

func f() T { return 0 }

func main() {
    println(f())
}

Expected result

$ go run ./sample.go
0

Got

$ yaegi ./sample.go
./sample.go:5:14: panic
./sample.go:8:10: panic
run: reflect.Set: value of type int is not assignable to type uint16
goroutine 1 [running]:
runtime/debug.Stack()
        runtime/debug/stack.go:24 +0x65
github.com/traefik/yaegi/interp.(*Interpreter).Execute.func1()
        github.com/traefik/yaegi/interp/program.go:141 +0x94
panic({0x5621aa425700, 0xc000156db0})
        runtime/panic.go:884 +0x212
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:192 +0x148
panic({0x5621aa425700, 0xc000156db0})
        runtime/panic.go:884 +0x212
github.com/traefik/yaegi/interp.runCfg.func1()
        github.com/traefik/yaegi/interp/run.go:192 +0x148
panic({0x5621aa425700, 0xc000156db0})
        runtime/panic.go:884 +0x212
reflect.Value.assignTo({0x5621aa424900?, 0xc0002fcbf8?, 0x0?}, {0x5621aa1e535e, 0xb}, 0x5621aa425980, 0x0)
        reflect/value.go:3145 +0x2a5
reflect.Value.Set({0x5621aa425980?, 0xc0002fcc10?, 0x5621a98be79f?}, {0x5621aa424900?, 0xc0002fcbf8?, 0x0?})
        reflect/value.go:2160 +0xeb
github.com/traefik/yaegi/interp._return.func1(0xc0000fc790)
        github.com/traefik/yaegi/interp/run.go:2435 +0x54
github.com/traefik/yaegi/interp.runCfg(0xc000460480, 0xc0000fc790, 0x1?, 0x1?)
        github.com/traefik/yaegi/interp/run.go:200 +0x29d
github.com/traefik/yaegi/interp.call.func9(0xc0000fc6e0)
        github.com/traefik/yaegi/interp/run.go:1438 +0x965
github.com/traefik/yaegi/interp.runCfg(0xc000461200, 0xc0000fc6e0, 0xc0004606c0?, 0x0?)
        github.com/traefik/yaegi/interp/run.go:200 +0x29d
github.com/traefik/yaegi/interp.(*Interpreter).run(0xc00011b440, 0xc0004606c0, 0xc0000fc630?)
        github.com/traefik/yaegi/interp/run.go:119 +0x38e
github.com/traefik/yaegi/interp.(*Interpreter).Execute(0xc00011b440, 0xc000462060)
        github.com/traefik/yaegi/interp/program.go:167 +0x24b
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc00011b440, {0xc000164770?, 0x65?}, {0x7ffe6ccff98a?, 0xc000164690?}, 0x65?)
        github.com/traefik/yaegi/interp/interp.go:561 +0x5c
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0xc00011b440, {0x7ffe6ccff98a, 0x1a})
        github.com/traefik/yaegi/interp/interp.go:510 +0xab
main.runFile(0x7ffe6ccff98a?, {0x7ffe6ccff98a, 0x1a}, 0x0)
        github.com/traefik/yaegi/cmd/yaegi/run.go:153 +0xee
main.run({0xc0000d0010?, 0x1, 0x1})
        github.com/traefik/yaegi/cmd/yaegi/run.go:116 +0xbec
main.main()
        github.com/traefik/yaegi/cmd/yaegi/yaegi.go:144 +0x2cb

Yaegi Version

v0.14.2

Additional Notes

This issue is related to #1458

mvertes avatar Oct 13 '22 12:10 mvertes