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

interface argument in variadic function call #1205

Closed
mvertes opened this issue Jul 27, 2021 · 0 comments · Fixed by #1207
Closed

interface argument in variadic function call #1205

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

Comments

@mvertes
Copy link
Member

mvertes commented Jul 27, 2021

The following program sample.go triggers an unexpected result

package main

type Option interface {
    apply()
}

func f(opts ...Option) {
    for _, opt := range opts {
        opt.apply()
    }
}

type T struct{}

func (t *T) apply() { println("in apply") }

func main() {
    opt := []Option{&T{}}
    f(opt[0], &T{}) // works
    f(opt...)       // fails
}

Expected result

$ go run ./sample.go
in apply
in apply
in apply

Got

$ yaegi ./sample.go
in apply
in apply
./sample.go:9:3: panic
./sample.go:20:2: panic
run: /Users/marc/yt/issue-1172-5.go:9:3: method not found: apply
goroutine 1 [running]:
runtime/debug.Stack(0x1, 0x140002faa00, 0x40)
	/Users/marc/sdk/go1.16.6/src/runtime/debug/stack.go:24 +0x88
github.com/traefik/yaegi/interp.(*Interpreter).eval.func1(0x1400023dbf0)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/interp.go:505 +0x94
panic(0x1011fcbc0, 0x140001a3020)
	/Users/marc/sdk/go1.16.6/src/runtime/panic.go:965 +0x14c
github.com/traefik/yaegi/interp.runCfg.func1(0x140001d6d10, 0x140004c6300, 0x1400023d9c0)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/run.go:185 +0x1e8
panic(0x1011fcbc0, 0x140001a3020)
	/Users/marc/sdk/go1.16.6/src/runtime/panic.go:965 +0x14c
github.com/traefik/yaegi/interp.runCfg.func1(0x140001d7130, 0x140001cfd00, 0x1400023d750)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/run.go:185 +0x1e8
panic(0x1011fcbc0, 0x140001a3020)
	/Users/marc/sdk/go1.16.6/src/runtime/panic.go:965 +0x14c
github.com/traefik/yaegi/interp.getMethodByName.func1(0x140001d7130, 0x140002f0900)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/run.go:1822 +0x614
github.com/traefik/yaegi/interp.runCfg(0x140001cfd00, 0x140001d7130)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/run.go:191 +0x8c
github.com/traefik/yaegi/interp.call.func6(0x140001d6d10, 0x140001ccf80)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/run.go:1283 +0xa28
github.com/traefik/yaegi/interp.runCfg(0x140004c6300, 0x140001d6d10)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/run.go:191 +0x8c
github.com/traefik/yaegi/interp.(*Interpreter).run(0x1400037e000, 0x140004c5700, 0x140001d6a50)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/run.go:122 +0x244
github.com/traefik/yaegi/interp.(*Interpreter).eval(0x1400037e000, 0x14000190600, 0xfc, 0x16f7237c0, 0x1e, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/interp.go:597 +0x5e8
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0x1400037e000, 0x16f7237c0, 0x1e, 0x14000190500, 0xfc, 0x0, 0x0, 0x0)
	/Users/marc/go/src/github.com/traefik/yaegi/interp/interp.go:419 +0xc4
main.runFile(0x1400037e000, 0x16f7237c0, 0x1e, 0x0, 0x0, 0x0)
	/Users/marc/go/src/github.com/traefik/yaegi/cmd/yaegi/run.go:149 +0x84
main.run(0x140001b8010, 0x1, 0x1, 0x14000186180, 0x14000073ea8)
	/Users/marc/go/src/github.com/traefik/yaegi/cmd/yaegi/run.go:112 +0x830
main.main()
	/Users/marc/go/src/github.com/traefik/yaegi/cmd/yaegi/yaegi.go:144 +0x324

Yaegi Version

0.9.21

Additional Notes

related to #1172

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