Skip to content

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

Description

@peakedshout

The following program sample.go triggers an unexpected result

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

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

Got

-

Yaegi Version

0.16.1

Additional Notes

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions