diff options
author | Jinzhu <wosmvp@gmail.com> | 2021-04-20 02:47:54 +0000 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2021-04-20 20:14:14 +0000 |
commit | 7473a6a0ebb270c24c20994d3ea6e3fd96def223 (patch) | |
tree | af2e810a3bee0a7f163a6fd465faab38a734682f /src/reflect/all_test.go | |
parent | fbb600b28349a41742d35f1d2417c5843c6ba6e4 (diff) | |
download | go-7473a6a0ebb270c24c20994d3ea6e3fd96def223.tar.gz go-7473a6a0ebb270c24c20994d3ea6e3fd96def223.zip |
reflect: fix stack overflow panic when using haveIdenticalUnderlyingType
haveIdenticalUnderlyingType raises stack overflow when compares
self-referential structs having same structure in different packages.
Change-Id: I7c79ab988edcffadcf7e0730a50b4d31b136bb6a
GitHub-Last-Rev: 4d4217f0c16ef14aa1f38ff7cf88c98755bb8ddd
GitHub-Pull-Request: golang/go#45543
Reviewed-on: https://go-review.googlesource.com/c/go/+/309729
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/reflect/all_test.go')
-rw-r--r-- | src/reflect/all_test.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index 241f6b0b5a..3269f5ffce 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -15,6 +15,8 @@ import ( "math/rand" "os" . "reflect" + "reflect/internal/example1" + "reflect/internal/example2" "runtime" "sort" "strconv" @@ -3808,6 +3810,16 @@ type Empty struct{} type MyStruct struct { x int `some:"tag"` } +type MyStruct1 struct { + x struct { + int `some:"bar"` + } +} +type MyStruct2 struct { + x struct { + int `some:"foo"` + } +} type MyString string type MyBytes []byte type MyRunes []int32 @@ -4158,6 +4170,9 @@ var convertTests = []struct { x int `some:"bar"` }{}), V(MyStruct{})}, + {V(MyStruct1{}), V(MyStruct2{})}, + {V(MyStruct2{}), V(MyStruct1{})}, + // can convert *byte and *MyByte {V((*byte)(nil)), V((*MyByte)(nil))}, {V((*MyByte)(nil)), V((*byte)(nil))}, @@ -7231,3 +7246,13 @@ func iterateToString(it *MapIter) string { sort.Strings(got) return "[" + strings.Join(got, ", ") + "]" } + +func TestConvertibleTo(t *testing.T) { + t1 := ValueOf(example1.MyStruct{}).Type() + t2 := ValueOf(example2.MyStruct{}).Type() + + // Shouldn't raise stack overflow + if t1.ConvertibleTo(t2) { + t.Fatalf("(%s).ConvertibleTo(%s) = true, want false", t1, t2) + } +} |