weak: fix weak pointer test to correctly iterate over weak pointers after GC

This change fixes a bug in the weak pointer test where the loop was
attempting to iterate over a nil slice (bt) instead of the weak
pointer slice (wt).

After setting bt to nil and running GC, the test should iterate over
the weak pointers to verify they've been cleared, not attempt to
iterate over the now-nil strong references.

Change-Id: Ic0425f59da132257770ed87d1bcea5d2c0a54e07
Reviewed-on: https://go-review.googlesource.com/c/go/+/723600
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
This commit is contained in:
cuishuang 2025-11-24 14:38:30 +08:00 committed by David Chase
parent a88a96330f
commit a33bbf1988

View File

@ -110,7 +110,7 @@ func TestPointerEquality(t *testing.T) {
bt = nil
// bt is no longer referenced.
runtime.GC()
for i := range bt {
for i := range wt {
st := wt[i].Value()
if st != nil {
t.Fatalf("expected weak pointer to be nil, got %p", st)