From b3388569a187ea6be48caa41265f2b4dbc2fdfd3 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Thu, 7 Aug 2025 15:30:54 -0700 Subject: reflect: handle zero-sized fields of directly-stored structures correctly type W struct { E struct{} X *byte } type W is a "direct" type. That is, it is a pointer-ish type that can be stored directly as the second word of an interface. But if we ask reflect for W's first field, that value must *not* be direct, as zero-sized things cannot be stored directly. This was a problem introduced in CL 681937. Before that, types like W were not eligible for directness. Fixes #74935 Change-Id: Idefb55c23eaa59153009f863bad611593981e5cb Reviewed-on: https://go-review.googlesource.com/c/go/+/694195 Auto-Submit: Keith Randall Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI Reviewed-by: Cuong Manh Le Reviewed-by: Dmitri Shuralyov --- test/fixedbugs/issue74935.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/fixedbugs/issue74935.go (limited to 'test/fixedbugs') diff --git a/test/fixedbugs/issue74935.go b/test/fixedbugs/issue74935.go new file mode 100644 index 0000000000..1f6f718b02 --- /dev/null +++ b/test/fixedbugs/issue74935.go @@ -0,0 +1,19 @@ +// 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() +} -- cgit v1.3-5-g9baa