Repository navigation
feat(reflect): add the Type iterators of Go 1.26, Method.IsExported and Method.Func - #539
Merged
Merged
Conversation
Go 1.26 added Type.Fields, Type.Methods, Type.Ins and Type.Outs, which return iterators. Code that ranges over them, such as a Go interpreter that walks the methods of a type, failed with a TypeError. They are now methods of every reflect type. Signed-off-by: Randall C. O'Reilly <oreilly@ucdavis.edu>
reflect.Method had no IsExported method, so code that filters the methods of a type by it failed with a TypeError. Signed-off-by: Randall C. O'Reilly <oreilly@ucdavis.edu>
Method.Func was a JavaScript function that returned undefined, while Go code uses it as a reflect.Value: m.Func.Type() and m.Func.Call(args) failed. It is now a func Value of the method type, taking the receiver first, and the zero Value for the methods of an interface type, as in Go. Signed-off-by: Randall C. O'Reilly <oreilly@ucdavis.edu>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Go 1.26 added Type.Fields, Type.Methods, Type.Ins and Type.Outs, which return iterators. goscript's reflect types did not have them, so code that ranges over them failed with a TypeError: a Go interpreter that walks the methods of a type crashed while compiling the first interpreted method. They are now methods of every reflect type, implemented once and shared by the type classes.
reflect.Method also had no IsExported method, which the same code calls to filter methods, and its Func field was a JavaScript function returning undefined rather than a reflect.Value, so m.Func.Type() and m.Func.Call failed. IsExported is added, and Func is now a func Value of the method type that takes the receiver first (the zero Value for interface methods, as in Go).
reflect_value_methods_more covers the four iterators, IsExported, and Func for value and pointer receivers.