#1725·yaegi

BUG: return <-ch will be panic: reflect: reflect.Value.Set using unaddressable value [recovered, repanicked]

Author: peakedshoutCreated Jun 3, 2026Updated Jun 3, 2026

The following program sample.go triggers an unexpected result

go
package main

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

func call() string {
	ch := make(chan string, 1)
	ch <- "ok"
	return <-ch
}

func main() {
	fmt.Println(call()) // ok

	j := interp.New(interp.Options{})
	_, _ = j.Eval(`package main

func Call() string {
	ch := make(chan string, 1)
	ch <- "ok"
	v:= <-ch
	return v
}
`)
	callAny, _ := j.Eval("main.Call")
	s := callAny.Interface().(func() string)() // ok
	fmt.Println(s)

	i := interp.New(interp.Options{})
	_, _ = i.Eval(`package main

func Call() string {
	ch := make(chan string, 1)
	ch <- "ok"
	return <-ch
}
`)
	callAny, _ = i.Eval("main.Call")
	s = callAny.Interface().(func() string)() // panic: reflect: reflect.Value.Set using unaddressable value [recovered, repanicked]
	fmt.Println(s)
}

Expected result

bash
ok
ok
4:8: panic: main.Call(...)
panic: reflect: reflect.Value.Set using unaddressable value [recovered, repanicked]

Got

bash
-

Yaegi Version

0.16.1

Additional Notes

return <-ch will be panic: reflect: reflect.Value.Set using unaddressable value [recovered, repanicked] ?