]> Cypherpunks.ru repositories - gostls13.git/commit
reflect: make Value.IsZero identical to v == zero
authorJoe Tsai <joetsai@digital-static.net>
Wed, 9 Aug 2023 18:17:42 +0000 (11:17 -0700)
committerJoseph Tsai <joetsai@digital-static.net>
Fri, 1 Sep 2023 23:20:30 +0000 (23:20 +0000)
commitc700c23cef4b6501c0ccce248db57e30683eea99
treee0eede806adc3f8531cef7510a020d8a04d2c72e
parent7015ed891c6f4e51ebaa642fce42ea8a1592b4e1
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>
doc/go1.22.html
src/reflect/all_test.go
src/reflect/value.go