Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conversion to interface at return #1179

Closed
mvertes opened this issue Jul 8, 2021 · 0 comments · Fixed by #1180
Closed

conversion to interface at return #1179

mvertes opened this issue Jul 8, 2021 · 0 comments · Fixed by #1180
Labels
area/core bug Something isn't working
Milestone

Comments

@mvertes
Copy link
Member

mvertes commented Jul 8, 2021

The following program sample.go triggers an unexpected result

package main

type I interface {
    F()
}

type T struct {
    Name string
}

func (t *T) F() { println("in F", t.Name) }

func newT(s string) *T { return &T{s} }

func NewI(s string) I { return newT(s) }

func main() {
    i := NewI("test")
    i.F()
}

Expected result

$ go run ./sample.go
in F test

Got

$ yaegi ./sample.go
./sample.go:19:2: panic
./sample.go:19:2: panic
run: reflect.Set: value of type interp.valueInterface is not assignable to type *struct { Name string }
goroutine 1 [running]:
runtime/debug.Stack(0x1, 0x14000302a00, 0x40)
	runtime/debug/stack.go:24 +0x88
github.com/traefik/yaegi/interp.(*Interpreter).eval.func1(0x14000247bf0)
	github.com/traefik/yaegi/interp/interp.go:503 +0x94
panic(0x100e8df00, 0x14000233350)
	runtime/panic.go:965 +0x14c
github.com/traefik/yaegi/interp.runCfg.func1(0x140001de790, 0x140004d3200, 0x140002479c0)
	github.com/traefik/yaegi/interp/run.go:185 +0x1e8
panic(0x100e8df00, 0x14000233350)
	runtime/panic.go:965 +0x14c
github.com/traefik/yaegi/interp.runCfg.func1(0x140001de840, 0x140004d2700, 0x14000247780)
	github.com/traefik/yaegi/interp/run.go:185 +0x1e8
panic(0x100e8df00, 0x14000233350)
	runtime/panic.go:965 +0x14c
reflect.Value.assignTo(0x100f107c0, 0x140001c32e0, 0x99, 0x100caa2df, 0xb, 0x140002f8840, 0x0, 0x140001c32e0, 0xef6ee0d46ab20e00, 0x140001c32e0)
	reflect/value.go:2451 +0x2d0
reflect.Value.Set(0x140002f8840, 0x140001be968, 0x196, 0x100f107c0, 0x140001c32e0, 0x99)
	reflect/value.go:1564 +0x94
github.com/traefik/yaegi/interp.call.func3(0x140001de840, 0x140001de8f0, 0x4, 0x140001c0fc0)
	github.com/traefik/yaegi/interp/run.go:1122 +0x174
github.com/traefik/yaegi/interp.call.func7(0x140001de840, 0x14000233320)
	github.com/traefik/yaegi/interp/run.go:1200 +0x2a4
github.com/traefik/yaegi/interp.runCfg(0x140004d2700, 0x140001de840)
	github.com/traefik/yaegi/interp/run.go:191 +0x8c
github.com/traefik/yaegi/interp.call.func7(0x140001de790, 0x100f69220)
	github.com/traefik/yaegi/interp/run.go:1280 +0xa20
github.com/traefik/yaegi/interp.runCfg(0x140004d3200, 0x140001de790)
	github.com/traefik/yaegi/interp/run.go:191 +0x8c
github.com/traefik/yaegi/interp.(*Interpreter).run(0x14000384000, 0x140004d2a00, 0x140001de6e0)
	github.com/traefik/yaegi/interp/run.go:122 +0x244
github.com/traefik/yaegi/interp.(*Interpreter).eval(0x14000384000, 0x1400018c700, 0xf3, 0x16f9a37d6, 0x1e, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	github.com/traefik/yaegi/interp/interp.go:595 +0x5e8
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0x14000384000, 0x16f9a37d6, 0x1e, 0x1400018c600, 0xf3, 0x0, 0x0, 0x0)
	github.com/traefik/yaegi/interp/interp.go:417 +0xc4
main.runFile(0x14000384000, 0x16f9a37d6, 0x1e, 0x0, 0x0, 0x0)
	github.com/traefik/yaegi/cmd/yaegi/run.go:149 +0x84
main.run(0x140001c2010, 0x1, 0x1, 0x14000182480, 0x14000073ea8)
	github.com/traefik/yaegi/cmd/yaegi/run.go:112 +0x830
main.main()
	github.com/traefik/yaegi/cmd/yaegi/yaegi.go:144 +0x324

Yaegi Version

v0.9.19

Additional Notes

related to #1172 (after applying #1174, #1176, #1178)

@mvertes mvertes added area/core bug Something isn't working labels Jul 8, 2021
@mvertes mvertes added this to the v0.9.x milestone Jul 8, 2021
mvertes added a commit that referenced this issue Jul 8, 2021
There is no need to wrap the return value of functions returning
an interface in a special case, since the refactoring of interfaces.

Fixes #1179.
mvertes added a commit that referenced this issue Jul 8, 2021
Special wrapping of interface value at return is no longer necessary and
must be avoided now.

Fixes #1179.
traefiker pushed a commit that referenced this issue Jul 8, 2021
Special wrapping of interface value at return is no longer necessary and
must be avoided now.

Fixes #1179.
traefiker pushed a commit that referenced this issue Jul 8, 2021
Special wrapping of interface value at return is no longer necessary and
must be avoided now.

Fixes #1179.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant