Skip to content

Conversation

rcoreilly
Copy link
Contributor

This PR fixes issues like #1457 #1601 by importing the source code for generic functions in extracted Go code, so that it can be interpreted in yaegi.

You need to add a //yaegi:add comment directive to functions to so import, as importing all generic functions might not be desirable or feasible. In particular, given the need to interpret the generic code, it can not access any non-exported functions, types, or fields.

The extracted code is wrapped in a GenericFunc string type value as below:

 	err := i.Use(Exports{
		"guthib.com/generic/generic": map[string]reflect.Value{
			"Hello": reflect.ValueOf(GenericFunc("func Hello[T any](v T) { println(v) }")),
		},
	})

This PR builds on #1642 which interacts with this code in extracting the function source.

@rcoreilly
Copy link
Contributor Author

This and all the other PRs from me should now be good in terms of passing tests and working in our "real world" codebase which uses a lot of generics.

@dzzzc
Copy link

dzzzc commented Oct 4, 2024

Excuse me, will this feature be merged into the main branch?

@rcoreilly
Copy link
Contributor Author

how about merging this one too -- then we can go back to using this official version instead of our fork :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants