]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: make Value.Comparable return true for nil interface value
authorJes Cok <xigua67damn@gmail.com>
Fri, 16 Feb 2024 21:16:29 +0000 (21:16 +0000)
committerGopher Robot <gobot@golang.org>
Sat, 17 Feb 2024 00:13:07 +0000 (00:13 +0000)
Fixes #65718

Change-Id: I0b3edf9085f2d71f915bdf8ff9d312509b438c5f
GitHub-Last-Rev: 9fb1ca1a631c648d1f38f75b1fcb2f878048706b
GitHub-Pull-Request: golang/go#65750
Reviewed-on: https://go-review.googlesource.com/c/go/+/564795
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/reflect/all_test.go
src/reflect/value.go

index e77537c9a513a5c6413d7e5d956f0aaf778e8c57..c85de721a03ee75f9b027b71a30a386ebc56c4e4 100644 (file)
@@ -8027,6 +8027,7 @@ func TestValue_Comparable(t *testing.T) {
        var a int
        var s []int
        var i interface{} = a
+       var iNil interface{}
        var iSlice interface{} = s
        var iArrayFalse interface{} = [2]interface{}{1, map[int]int{}}
        var iArrayTrue interface{} = [2]interface{}{1, struct{ I interface{} }{1}}
@@ -8035,6 +8036,11 @@ func TestValue_Comparable(t *testing.T) {
                comparable bool
                deref      bool
        }{
+               {
+                       ValueOf(&iNil),
+                       true,
+                       true,
+               },
                {
                        ValueOf(32),
                        true,
index 87e595155bcd4592b1e4308b57e7e993b7d836a2..adb81d4641c4dce3249228c279b64a66edbf0fd0 100644 (file)
@@ -3406,7 +3406,7 @@ func (v Value) Comparable() bool {
                return v.Type().Comparable()
 
        case Interface:
-               return v.Elem().Comparable()
+               return v.IsNil() || v.Elem().Comparable()
 
        case Struct:
                for i := 0; i < v.NumField(); i++ {