go/src/reflect
Joe Tsai c700c23cef reflect: make Value.IsZero identical to v == zero
The upcoming built-in zero value provides an idiomatic way
to test for zero by comparing to the zero literal: v == zero.

The reflect package is meant to provide a programmatic way to perform
operations that the Go language itself provides.
Thus, it seems prudent that reflect.ValueOf(&v).Elem().IsZero() is
identical to v == zero.

This change alters the behavior of Value.IsZero in two concrete ways:
* negative zero is identical to zero
* blank fields in a struct are ignored

Prior to this change, we were already in an inconsistent state
due to a regression introduced by CL 411478.
The new behavior was already the case for comparable composite types.
This change makes it consistent for all other types
(in particular incomparable composite types and standalone numbers).

Updates #61372
Fixes #61827

Change-Id: Id23fb97eb3b8921417cc75a1d3ead963e22dc3d9
Reviewed-on: https://go-review.googlesource.com/c/go/+/517777
Reviewed-by: Russ Cox <rsc@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-09-01 23:20:30 +00:00
..
internal
abi.go reflect: replacing almost all use of *rtype with *abi.Type 2023-05-11 01:43:04 +00:00
abi_test.go
all_test.go reflect: make Value.IsZero identical to v == zero 2023-09-01 23:20:30 +00:00
arena.go reflect: fix ArenaNew to match documentation 2023-06-16 17:08:43 +00:00
asm_386.s
asm_amd64.s
asm_arm.s
asm_arm64.s
asm_loong64.s
asm_mips64x.s
asm_mipsx.s
asm_ppc64x.s
asm_riscv64.s
asm_s390x.s
asm_wasm.s
benchmark_test.go reflect: optimize DeepEqual() for maps 2023-07-31 15:44:01 +00:00
deepequal.go reflect: optimize DeepEqual() for maps 2023-07-31 15:44:01 +00:00
example_test.go
export_test.go Revert "reflect: change rtype so that it (not *rtype) implements Type" 2023-05-12 13:32:40 +00:00
float32reg_generic.go
float32reg_ppc64x.s
float32reg_riscv64.s
makefunc.go reflect: do not escape Value.Type 2023-05-12 21:11:51 +00:00
nih_test.go
set_test.go
stubs_ppc64x.go
stubs_riscv64.go
swapper.go reflect: replacing almost all use of *rtype with *abi.Type 2023-05-11 01:43:04 +00:00
tostring_test.go
type.go reflect: update Type.FieldByName documentation 2023-08-02 15:25:06 +00:00
type_test.go reflect: add TypeFor 2023-07-31 15:50:15 +00:00
value.go reflect: make Value.IsZero identical to v == zero 2023-09-01 23:20:30 +00:00
visiblefields.go
visiblefields_test.go