]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json, text/template: use reflect.Value.Equal instead of ==
authorEmmanuel T Odeke <emmanuel@orijtech.com>
Fri, 8 Nov 2024 01:40:08 +0000 (17:40 -0800)
committerGopher Robot <gobot@golang.org>
Fri, 8 Nov 2024 16:09:21 +0000 (16:09 +0000)
This change applies a fix for a reflect.Value incorrect comparison
using "==" or reflect.DeepEqual.
This change is a precursor to the change that'll bring in the
static analyzer "reflectvaluecompare", by ensuring that all tests
pass beforehand.

Updates #43993

Change-Id: I6c47eb0a1de6353ac7495cb8cb49b318b7ebba56
Reviewed-on: https://go-review.googlesource.com/c/go/+/626116
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/encoding/json/decode.go
src/text/template/exec.go

index 1a05ef59a2c5345f8b03489ea3878b7cf36cbe95..98102291ab803632b3a62890da9f3f525e6c0e9b 100644 (file)
@@ -472,7 +472,7 @@ func indirect(v reflect.Value, decodingNull bool) (Unmarshaler, encoding.TextUnm
                // Prevent infinite loop if v is an interface pointing to its own address:
                //     var v any
                //     v = &v
-               if v.Elem().Kind() == reflect.Interface && v.Elem().Elem() == v {
+               if v.Elem().Kind() == reflect.Interface && v.Elem().Elem().Equal(v) {
                        v = v.Elem()
                        break
                }
index 872d8aaa0cce6ac4984ba8f2ab60ce446eaee546..57f076e35f1c87b044b9bf891025495a0585da1b 100644 (file)
@@ -810,7 +810,7 @@ func (s *state) evalCall(dot, fun reflect.Value, isBuiltin bool, node parse.Node
                                return v
                        }
                }
-               if final != missingVal {
+               if !final.Equal(missingVal) {
                        // The last argument to and/or is coming from
                        // the pipeline. We didn't short circuit on an earlier
                        // argument, so we are going to return this one.