]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: fix isRegularMemory at case Array
authorJes Cok <xigua67damn@gmail.com>
Wed, 24 Jan 2024 12:33:30 +0000 (12:33 +0000)
committerCherry Mui <cherryyz@google.com>
Wed, 24 Jan 2024 16:55:23 +0000 (16:55 +0000)
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>

src/reflect/type.go
src/reflect/type_test.go

index dfa2ff6ddf61f36e63d9fe3b768ba16c5e7d9d47..110e2c9d198c9cf5d005642b14e1dfa340e4a41f 100644 (file)
@@ -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:
index d53bbe553dcc27c250db4c23f04161a386d54e52..4ba4536d66eec772feec721304fb07e032c6770f 100644 (file)
@@ -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