]> Cypherpunks repositories - gostls13.git/commitdiff
Revert "reflect: handle zero-sized fields of directly-stored structures correctly"
authorKeith Randall <khr@golang.org>
Tue, 12 Aug 2025 00:29:11 +0000 (17:29 -0700)
committerKeith Randall <khr@golang.org>
Tue, 12 Aug 2025 05:36:13 +0000 (22:36 -0700)
This reverts commit b3388569a187ea6be48caa41265f2b4dbc2fdfd3 (CL 694195)

Reason for revert: still causing compiler failures on Google test code

Change-Id: I2a9b0f9a57fe2b6977238bbfbefb572545210b9f
Reviewed-on: https://go-review.googlesource.com/c/go/+/694995
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
src/reflect/value.go
test/fixedbugs/issue74935.go [deleted file]

index e2ca0d89dd6d9ce87bff7840c0981621748db6c8..6f65ef81dc3ae3dea0c989572319c7011c1d4a23 100644 (file)
@@ -1277,17 +1277,6 @@ func (v Value) Field(i int) Value {
                        fl |= flagStickyRO
                }
        }
-       if fl&flagIndir == 0 && typ.Size() == 0 {
-               // Special case for picking a field out of a direct struct.
-               // A direct struct must have a pointer field and possibly a
-               // bunch of zero-sized fields. We must return the zero-sized
-               // fields indirectly, as only ptr-shaped things can be direct.
-               // See issue 74935.
-               // We use nil instead of v.ptr as it doesn't matter and
-               // we can avoid pinning a possibly now-unused object.
-               return Value{typ, nil, fl | flagIndir}
-       }
-
        // Either flagIndir is set and v.ptr points at struct,
        // or flagIndir is not set and v.ptr is the actual struct data.
        // In the former case, we want v.ptr + offset.
diff --git a/test/fixedbugs/issue74935.go b/test/fixedbugs/issue74935.go
deleted file mode 100644 (file)
index 1f6f718..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// run
-
-// Copyright 2025 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package main
-
-import "reflect"
-
-type W struct {
-       E struct{}
-       X *byte
-}
-
-func main() {
-       w := reflect.ValueOf(W{})
-       _ = w.Field(0).Interface()
-}