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 lookup fails on on struct with interface field #1208

Closed
mvertes opened this issue Jul 28, 2021 · 1 comment · Fixed by #1209
Closed

method lookup fails on on struct with interface field #1208

mvertes opened this issue Jul 28, 2021 · 1 comment · Fixed by #1209
Labels
area/core bug Something isn't working
Milestone

Comments

@mvertes
Copy link
Member

mvertes commented Jul 28, 2021

The following program sample.go triggers an unexpected result

package main

type Core interface {
    Enabler
}

type Enabler interface {
    Enabled() bool
}

type Logger struct {
    core Core
}

func (log *Logger) GetCore() Core { return log.core }

type T struct{}

func (t *T) Enabled() bool { return true }

func main() {
    base := &Logger{&T{}}
    println(base.GetCore().Enabled())
}

Expected result

$ go run ./sample.go
true

Got

$ yaegi ./sample.go
./sample.go:23:10: panic
run: runtime error: invalid memory address or nil pointer dereference
goroutine 1 [running]:
runtime/debug.Stack(0x1, 0x14000090400, 0x40)
	/Users/marc/sdk/go1.16.6/src/runtime/debug/stack.go:24 +0x88
github.com/traefik/yaegi/interp.(*Interpreter).eval.func1(0x140000a5bf0)
	/Users/marc/go/src/github.com/traefik/yaegi2/interp/interp.go:504 +0x94
panic(0x104adcf20, 0x10506eae0)
	/Users/marc/sdk/go1.16.6/src/runtime/panic.go:965 +0x14c
github.com/traefik/yaegi/interp.runCfg.func1(0x1400036e160, 0x14000095100, 0x140000a59c0)
	/Users/marc/go/src/github.com/traefik/yaegi2/interp/run.go:185 +0x1e8
panic(0x104adcf20, 0x10506eae0)
	/Users/marc/sdk/go1.16.6/src/runtime/panic.go:965 +0x14c
github.com/traefik/yaegi/interp.getMethodByName.func1(0x1400036e160, 0x1400011ab40)
	/Users/marc/go/src/github.com/traefik/yaegi2/interp/run.go:1845 +0x174
github.com/traefik/yaegi/interp.runCfg(0x14000095100, 0x1400036e160)
	/Users/marc/go/src/github.com/traefik/yaegi2/interp/run.go:191 +0x8c
github.com/traefik/yaegi/interp.(*Interpreter).run(0x1400036c000, 0x14000094500, 0x1400036e000)
	/Users/marc/go/src/github.com/traefik/yaegi2/interp/run.go:122 +0x244
github.com/traefik/yaegi/interp.(*Interpreter).eval(0x1400036c000, 0x140001c69a0, 0x151, 0x16bd9b798, 0x1e, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/marc/go/src/github.com/traefik/yaegi2/interp/interp.go:596 +0x5e8
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0x1400036c000, 0x16bd9b798, 0x1e, 0x140001c6800, 0x151, 0x0, 0x0, 0x0)
	/Users/marc/go/src/github.com/traefik/yaegi2/interp/interp.go:418 +0xc4
main.runFile(0x1400036c000, 0x16bd9b798, 0x1e, 0x0, 0x0, 0x0)
	/Users/marc/go/src/github.com/traefik/yaegi2/cmd/yaegi/run.go:149 +0x84
main.run(0x140001c0010, 0x1, 0x1, 0x14000182480, 0x14000073ea8)
	/Users/marc/go/src/github.com/traefik/yaegi2/cmd/yaegi/run.go:112 +0x830
main.main()
	/Users/marc/go/src/github.com/traefik/yaegi2/cmd/yaegi/yaegi.go:144 +0x324

Yaegi Version

0.9.21

Additional Notes

No response

@mvertes
Copy link
Member Author

mvertes commented Jul 28, 2021

issue related to #1172, after #1207 is applied.

mvertes added a commit that referenced this issue Jul 31, 2021
Wrap non empty interface value  in struct field, to allow method
lookup.

Fixes #1208.
@mvertes mvertes added area/core bug Something isn't working labels Jul 31, 2021
@mvertes mvertes added this to the v0.9.x milestone Jul 31, 2021
traefiker pushed a commit that referenced this issue Aug 6, 2021
Wrap non empty interface value  in struct field, to allow method
lookup.

Fixes #1208.
traefiker pushed a commit that referenced this issue Aug 6, 2021
Wrap non empty interface value  in struct field, to allow method
lookup.

Fixes #1208.
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