]> Cypherpunks repositories - gostls13.git/commit
weak: don't panic when calling Value on a zero Pointer
authorMichael Anthony Knyszek <mknyszek@google.com>
Tue, 7 Jan 2025 16:01:46 +0000 (16:01 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 7 Jan 2025 18:08:42 +0000 (10:08 -0800)
commitd62154db837fef880714f710bafbe0af94034b40
treebe95a2ae6eeebc994b14161e975e4c2841b788d9
parent9d0772b23ed8dae1667a3328a72f384eccf812d7
weak: don't panic when calling Value on a zero Pointer

Currently weak.Pointer.Value will panic if the weak.Pointer is
uninitialized (zero value) which goes against it's documentation. Fix
this and add a test. While we're here, also add a test to ensure
weak.Make[T](nil) is equivalent to the zero value of weak.Pointer[T].

Fixes #71153.

Change-Id: I4d9196026360bc42a5bfcb33ce449131ec251dba
Reviewed-on: https://go-review.googlesource.com/c/go/+/641095
Reviewed-by: David Finkel <david.finkel@gmail.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
src/weak/pointer.go
src/weak/pointer_test.go