aboutsummaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorJes Cok <xigua67damn@gmail.com>2024-01-24 12:33:30 +0000
committerCherry Mui <cherryyz@google.com>2024-01-24 16:55:23 +0000
commit3330c69476f4d8bca40a9fb6b429a0401f24f2b7 (patch)
tree3a3af96869d0dc6fbed8d6f9cd73ef8e5d5faa00 /src/reflect
parent6037c8a87745f96307bb4ffab965aa39f4cf1806 (diff)
downloadgo-3330c69476f4d8bca40a9fb6b429a0401f24f2b7.tar.gz
go-3330c69476f4d8bca40a9fb6b429a0401f24f2b7.zip
reflect: fix isRegularMemory at case Array
To match cmd/compile/internal/compare.IsRegularMemory, this CL adds code for empty arrays of comparable element type. Change-Id: I205fb9bfda60be6c9aac2d9098ed3f0eb51cd0fa GitHub-Last-Rev: 40db7ed510883633374895271145678a51418426 GitHub-Pull-Request: golang/go#65252 Reviewed-on: https://go-review.googlesource.com/c/go/+/558155 Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/type.go6
-rw-r--r--src/reflect/type_test.go3
2 files changed, 8 insertions, 1 deletions
diff --git a/src/reflect/type.go b/src/reflect/type.go
index dfa2ff6ddf..110e2c9d19 100644
--- a/src/reflect/type.go
+++ b/src/reflect/type.go
@@ -2156,7 +2156,11 @@ func isValidFieldName(fieldName string) bool {
func isRegularMemory(t Type) bool {
switch t.Kind() {
case Array:
- return isRegularMemory(t.Elem())
+ elem := t.Elem()
+ if isRegularMemory(elem) {
+ return true
+ }
+ return elem.Comparable() && t.Len() == 0
case Int8, Int16, Int32, Int64, Int, Uint8, Uint16, Uint32, Uint64, Uint, Uintptr, Chan, Pointer, Bool, UnsafePointer:
return true
case Struct:
diff --git a/src/reflect/type_test.go b/src/reflect/type_test.go
index d53bbe553d..4ba4536d66 100644
--- a/src/reflect/type_test.go
+++ b/src/reflect/type_test.go
@@ -78,6 +78,9 @@ func TestIsRegularMemory(t *testing.T) {
}{})}, true},
{"map[int][int]", args{reflect.TypeOf(map[int]int{})}, false},
{"[4]chan int", args{reflect.TypeOf([4]chan int{})}, true},
+ {"[0]struct{_ S}", args{reflect.TypeOf([0]struct {
+ _ S
+ }{})}, true},
{"struct{i int; _ S}", args{reflect.TypeOf(struct {
i int
_ S