Skip to content

feat(reflect): add the Type iterators of Go 1.26, Method.IsExported and Method.Func - #539

Merged
paralin merged 3 commits into
s4wave:devfrom
cogentcore:feat/reflect-type-iterators
Oct 25, 2026
Merged

paralin merged 3 commits into
s4wave:devfrom
cogentcore:feat/reflect-type-iterators

Conversation

@rcoreilly

@rcoreilly rcoreilly commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

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.

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>
@rcoreilly rcoreilly changed the title feat(reflect): add the Type iterators of Go 1.26 and Method.IsExported feat(reflect): add the Type iterators of Go 1.26, Method.IsExported and Method.Func Oct 25, 2026
@paralin
paralin changed the base branch from master to dev October 25, 2026 18:37
@paralin
paralin merged commit eedc483 into s4wave:dev Oct 25, 2026
7 checks passed
@paralin

paralin commented Oct 25, 2026

Copy link
Copy Markdown
Member

Landed on master as 7911cbb, bc7757c, 3e00b85, rebased onto the batch #532 to #550, with regenerated fixtures in fca8071. Wrote the iterator methods of InvalidTypeClass in that class's compact style.

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.

2 participants