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

Can't append to struct's slice of functions #1459

Closed
danielnovograd opened this issue Sep 21, 2022 · 0 comments · Fixed by #1469
Closed

Can't append to struct's slice of functions #1459

danielnovograd opened this issue Sep 21, 2022 · 0 comments · Fixed by #1469
Labels
area/core bug Something isn't working

Comments

@danielnovograd
Copy link

The following program sample.go triggers an unexpected result

package main

import "fmt"

type funclistItem func()

type funclist struct {
	list []funclistItem
}

func main() {
	funcs := funclist{}

	funcs.list = append(funcs.list, func() { fmt.Println("first") })

	for _, f := range funcs.list {
		f()
	}
}

Expected result

$ go run ./sample.go
// first

Got

$ yaegi ./sample.go
// reflect.Set: value of type *interp.node is not assignable to type func()

Yaegi Version

0218249

Additional Notes

First noticed this when trying to append a list of custom function types, but also breaks with func literals.

@mvertes mvertes added bug Something isn't working area/core labels Sep 21, 2022
mvertes added a commit to mvertes/yaegi that referenced this issue Oct 11, 2022
Up to now functions could be stored as node values in frame
(as for interpreter defined functions) or function values,
directly callable by the Go runtime. We now always store functions
in the later form, making the processing of functions, anonymous
closures and methods simpler and more robust. All functions, once
compiled are always directly callable, with no further wrapping
necessary.

Fixes traefik#1459.
traefiker pushed a commit to mvertes/yaegi that referenced this issue Oct 19, 2022
Up to now functions could be stored as node values in frame
(as for interpreter defined functions) or function values,
directly callable by the Go runtime. We now always store functions
in the later form, making the processing of functions, anonymous
closures and methods simpler and more robust. All functions, once
compiled are always directly callable, with no further wrapping
necessary.

Fixes traefik#1459.
traefiker pushed a commit that referenced this issue Oct 19, 2022
Up to now functions could be stored as node values in frame (as for interpreter defined functions) or function values, directly callable by the Go runtime. We now always store functions in the later form, making the processing of functions, anonymous closures and methods simpler and more robust. All functions, once compiled are always directly callable, with no further wrapping necessary.

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