reflect: Value.Methods should panic at nil interface value

Change-Id: Iac3a162a93e4b8680902b282c8f8f77129ab91bf
GitHub-Last-Rev: b857486317
GitHub-Pull-Request: golang/go#78935
Reviewed-on: https://go-review.googlesource.com/c/go/+/770420
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Weixie Cui 2026-04-24 15:40:43 +00:00 committed by Keith Randall
parent c5b875218f
commit 891f4a8711

View file

@ -2678,9 +2678,10 @@ func (v Value) Fields() iter.Seq2[StructField, Value] {
// Calling this method will force the linker to retain all exported methods in all packages.
// This may make the executable binary larger but will not affect execution time.
func (v Value) Methods() iter.Seq2[Method, Value] {
rtype := v.Type()
n := v.NumMethod()
return func(yield func(Method, Value) bool) {
rtype := v.Type()
for i := range v.NumMethod() {
for i := range n {
if !yield(rtype.Method(i), v.Method(i)) {
return
}