]> Cypherpunks repositories - gostls13.git/commit
text/template: permit eq and ne funcs to check against nil
authorRob Pike <r@golang.org>
Mon, 14 Mar 2022 02:21:06 +0000 (13:21 +1100)
committerIan Lance Taylor <iant@golang.org>
Mon, 4 Apr 2022 17:28:30 +0000 (17:28 +0000)
commitc58f1bb65f2187d79a5842bb19f4db4cafd22794
treefb395d191315738c8dfd0fa2cabd0439336906f1
parentac313524fe4997b80a4221647f0da79d0e07b88e
text/template: permit eq and ne funcs to check against nil

The existing code errors out immediately if the argument is not
"comparable", making it impossible to test a slice, map, and so
on from being compared to nil.

Fix by delaying the "comparable" error check until we encounter
an actual check between two non-comparable, non-nil values.

Note for the future: reflect makes it unnecessarily clumsy
to deal with nil values in cases like this. For instance, it
should be possible to check if a value is nil without stepping
around a panic. See the new functions isNil and canCompare
for my (too expensive) workaround.

Fixes #51642

Change-Id: Ic4072698c4910130ea7e3d76e7a148d8a8b88162
Reviewed-on: https://go-review.googlesource.com/c/go/+/392274
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Cherry Mui <cherryyz@google.com>
src/html/template/exec_test.go
src/text/template/exec_test.go
src/text/template/funcs.go