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

method resolution on an embedded interface #1439

Closed
mvertes opened this issue Aug 10, 2022 · 0 comments · Fixed by #1441
Closed

method resolution on an embedded interface #1439

mvertes opened this issue Aug 10, 2022 · 0 comments · Fixed by #1441
Labels
area/core bug Something isn't working
Milestone

Comments

@mvertes
Copy link
Member

mvertes commented Aug 10, 2022

The following program sample.go triggers an unexpected result

package main

type Transformer interface {
    Reset()
}
    
type Encoder struct {
    Transformer
}   
    
type nop struct{}

func (nop) Reset() { println("Reset") }

func f(e Transformer) {
    e.Reset()
}
    
func main() {
    e := Encoder{Transformer: nop{}}
    f(e)
}

Expected result

$ go run ./sample.go
Reset

Got

./yaegi ~/sample.go 
/Users/marc/sample.go:16:2: panic
/Users/marc/sample.go:20:28: panic
run: /Users/marc/sample.go:16:2: method not found: Reset
goroutine 1 [running]:
runtime/debug.Stack()
	/Users/marc/sdk/go1.19/src/runtime/debug/stack.go:24 +0x64
github.com/traefik/yaegi/interp.(*Interpreter).Execute.func1()
	/Users/marc/go/src/github.com/traefik/yaegi/interp/program.go:141 +0x74
panic({0x1034ddf00, 0x1400020c768})
	/Users/marc/sdk/go1.19/src/runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
	/Users/marc/go/src/github.com/traefik/yaegi/interp/run.go:192 +0x13c
panic({0x1034ddf00, 0x1400020c768})
	/Users/marc/sdk/go1.19/src/runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.runCfg.func1()
	/Users/marc/go/src/github.com/traefik/yaegi/interp/run.go:192 +0x13c
panic({0x1034ddf00, 0x1400020c768})
	/Users/marc/sdk/go1.19/src/runtime/panic.go:884 +0x204
github.com/traefik/yaegi/interp.getMethodByName.func1(0x14000358160)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/run.go:1968 +0x538
github.com/traefik/yaegi/interp.runCfg(0x140004bdc20, 0x14000358160, 0xffffffffffffffff?, 0x1034663a0?)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/run.go:200 +0x21c
github.com/traefik/yaegi/interp.call.func9(0x140003580b0)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/run.go:1433 +0x7c0
github.com/traefik/yaegi/interp.runCfg(0x140004beea0, 0x140003580b0, 0x0?, 0x0?)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/run.go:200 +0x21c
github.com/traefik/yaegi/interp.(*Interpreter).run(0x14000356000, 0x140004be000, 0x14000358000?)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/run.go:119 +0x3a8
github.com/traefik/yaegi/interp.(*Interpreter).Execute(0x14000356000, 0x14000437c20)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/program.go:167 +0x1cc
github.com/traefik/yaegi/interp.(*Interpreter).eval(0x14000356000, {0x1400031a400?, 0xf7?}, {0x16d4bf778?, 0x1400031a200?}, 0xf7?)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/interp.go:621 +0x64
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0x14000356000, {0x16d4bf778, 0x1e})
	/Users/marc/go/src/github.com/traefik/yaegi/interp/interp.go:514 +0xa4
main.runFile(0x16d4bf778?, {0x16d4bf778, 0x1e}, 0x0)
	/Users/marc/go/src/github.com/traefik/yaegi/cmd/yaegi/run.go:153 +0xe8
main.run({0x14000032050?, 0x1, 0x1})
	/Users/marc/go/src/github.com/traefik/yaegi/cmd/yaegi/run.go:116 +0xb2c
main.main()
	/Users/marc/go/src/github.com/traefik/yaegi/cmd/yaegi/yaegi.go:144 +0x300

Yaegi Version

v0.14.1

Additional Notes

Same issue as in #1427 once #1438 is applied.

@mvertes mvertes added bug Something isn't working area/core labels Aug 11, 2022
traefiker pushed a commit that referenced this issue Aug 17, 2022
The function `getMethodByName()` is now able to look for
embedded `valueInterface` field for matching methods in interface
struct fields.
    
Fixes #1439 and #1427.
@traefiker traefiker added this to the v0.14.x milestone Aug 17, 2022
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.

2 participants