reflect: fix StructOf panics from too many methods in embedded fields

Previously we panicked if the number of methods present for an embedded
field was >= 32. This change removes that limit and now StructOf
dynamically calls itself to create space for the number of methods.

Fixes #25402

Change-Id: I3b1deb119796d25f7e6eee1cdb126327b49a0b5e
GitHub-Last-Rev: 16da71ad6b
GitHub-Pull-Request: golang/go#26865
Reviewed-on: https://go-review.googlesource.com/c/128479
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Raghavendra Nagaraj 2018-11-06 09:02:03 +00:00 committed by Ian Lance Taylor
parent 510eea2dfc
commit 0e4a0b93d2
2 changed files with 30 additions and 60 deletions

View file

@ -5019,6 +5019,17 @@ func TestStructOfWithInterface(t *testing.T) {
})
}
func TestStructOfTooManyFields(t *testing.T) {
// Bug Fix: #25402 - this should not panic
tt := StructOf([]StructField{
{Name: "Time", Type: TypeOf(time.Time{}), Anonymous: true},
})
if _, present := tt.MethodByName("After"); !present {
t.Errorf("Expected method `After` to be found")
}
}
func TestChanOf(t *testing.T) {
// check construction and use of type not in binary
type T string