Skip to content

Commit 3330c69

Browse files
callthingsoffcherrymui
authored andcommitted
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: 40db7ed GitHub-Pull-Request: #65252 Reviewed-on: https://go-review.googlesource.com/c/go/+/558155 Reviewed-by: Keith Randall <[email protected]> Run-TryBot: qiulaidongfeng <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: qiulaidongfeng <[email protected]> Reviewed-by: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 6037c8a commit 3330c69

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/reflect/type.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -2156,7 +2156,11 @@ func isValidFieldName(fieldName string) bool {
21562156
func isRegularMemory(t Type) bool {
21572157
switch t.Kind() {
21582158
case Array:
2159-
return isRegularMemory(t.Elem())
2159+
elem := t.Elem()
2160+
if isRegularMemory(elem) {
2161+
return true
2162+
}
2163+
return elem.Comparable() && t.Len() == 0
21602164
case Int8, Int16, Int32, Int64, Int, Uint8, Uint16, Uint32, Uint64, Uint, Uintptr, Chan, Pointer, Bool, UnsafePointer:
21612165
return true
21622166
case Struct:

src/reflect/type_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ func TestIsRegularMemory(t *testing.T) {
7878
}{})}, true},
7979
{"map[int][int]", args{reflect.TypeOf(map[int]int{})}, false},
8080
{"[4]chan int", args{reflect.TypeOf([4]chan int{})}, true},
81+
{"[0]struct{_ S}", args{reflect.TypeOf([0]struct {
82+
_ S
83+
}{})}, true},
8184
{"struct{i int; _ S}", args{reflect.TypeOf(struct {
8285
i int
8386
_ S

0 commit comments

Comments
 (0)