Skip to content

panic: "call of reflect.Value.IsNil on struct Value" for interface conversion in subexpression #1719

@tom93

Description

@tom93

The following program sample.go triggers an unexpected result

package main

type X struct{}

func main() {
	x := X{}
	println(interface{}(x) != nil)
}

Expected result

$ go run ./sample.go
true

Got

$ yaegi ./sample.go
sample.go:6:7: panic: main.main(...)
run: reflect: call of reflect.Value.IsNil on struct Value
goroutine 1 [running]:
runtime/debug.Stack()
	/home/user/gox/src/runtime/debug/stack.go:26 +0x5e
github.com/traefik/yaegi/interp.(*Interpreter).Execute.func1()
	/home/user/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/program.go:146 +0x79
panic({0xe48440?, 0x71908244e40?})
	/home/user/gox/src/runtime/panic.go:860 +0x13a
github.com/traefik/yaegi/interp.runCfg.func1()
	/home/user/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/run.go:226 +0x1a5
panic({0xe48440?, 0x71908244e40?})
	/home/user/gox/src/runtime/panic.go:860 +0x13a
reflect.Value.IsNil(...)
	/home/user/gox/src/reflect/value.go:1649
github.com/traefik/yaegi/interp.isNotNil.func2(0x71907f5e2c0)
	/home/user/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/run.go:4001 +0x108
github.com/traefik/yaegi/interp.runCfg(0x71908335040, 0x71907f5e2c0, 0x4?, 0x0?)
	/home/user/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/run.go:234 +0x265
github.com/traefik/yaegi/interp.(*Interpreter).run(0x71907f75448, 0x71908334500, 0x71907f5e210?)
	/home/user/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/run.go:119 +0x36d
github.com/traefik/yaegi/interp.(*Interpreter).Execute(0x71907f75448, 0x71908328a20)
	/home/user/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/program.go:172 +0x225
github.com/traefik/yaegi/interp.(*Interpreter).eval(0x71907f75448, {0x7190826e1e0?, 0x5a?}, {0x7ffe5e184937?, 0x71908287b00?}, 0x20?)
	/home/user/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/interp.go:563 +0x55
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0x71907f75448, {0x7ffe5e184937, 0x9})
	/home/user/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/interp/interp.go:512 +0xa6
main.runFile(0x71907f75448, {0x7ffe5e184937, 0x9}, 0x0)
	/home/user/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/cmd/yaegi/run.go:153 +0xd8
main.run({0x71907ebe150, 0x1, 0x1})
	/home/user/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/cmd/yaegi/run.go:116 +0x998
main.main()
	/home/user/go/pkg/mod/github.com/traefik/yaegi@v0.16.1/cmd/yaegi/yaegi.go:144 +0x2d7

Yaegi Version

v0.16.1

Additional Notes

If I factor the conversion out it works correctly:

package main

type X struct{}

func main() {
	x := X{}
	i := interface{}(x)
	println(i != nil)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions