From 10224a4bf87709ee98a8248aa1a4889b8d532e8e Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Tue, 30 Jun 2026 09:26:55 -0700 Subject: [PATCH] reflect,reflectlite: make IsRO/MakeRO package methods Having them as methods on reflectlite.Value makes them visible to the user. Also move new functions out of all_test.go so it can stay closer to upstream (except for comments). --- src/internal/reflectlite/value.go | 15 +++++++++++---- src/reflect/all_test.go | 8 -------- src/reflect/value_test.go | 11 +++++++++++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/internal/reflectlite/value.go b/src/internal/reflectlite/value.go index 36cdac11e..b353b1a92 100644 --- a/src/internal/reflectlite/value.go +++ b/src/internal/reflectlite/value.go @@ -47,11 +47,18 @@ func (v Value) isExported() bool { return v.flags&valueFlagExported != 0 } -func (v Value) IsRO() bool { +func (v Value) isRO() bool { return v.flags&(valueFlagRO) != 0 } -func (v Value) MakeRO(ro bool) Value { +// These are package methods, not methods on Value, since the reflect.Value embeds a reflectlite.Value, so any +// methods added to reflectlite.Value are visible to the user. + +func IsRO(v Value) bool { + return v.isRO() +} + +func MakeRO(v Value, ro bool) Value { if ro { v.flags |= valueFlagRO } else { @@ -61,7 +68,7 @@ func (v Value) MakeRO(ro bool) Value { } func (v Value) checkRO() { - if v.IsRO() { + if v.isRO() { panic("reflect: value is not settable") } } @@ -306,7 +313,7 @@ func (v Value) IsValid() bool { } func (v Value) CanInterface() bool { - return v.isExported() && !v.IsRO() + return v.isExported() && !v.isRO() } func (v Value) CanAddr() bool { diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index 7584c6205..ee4f1c5ef 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -4722,14 +4722,6 @@ var convertTests = []struct { } -func IsRO(v Value) bool { - return v.IsRO() -} - -func MakeRO(v Value) Value { - return Value{v.MakeRO(true)} -} - func TestConvert(t *testing.T) { canConvert := map[[2]Type]bool{} all := map[Type]bool{} diff --git a/src/reflect/value_test.go b/src/reflect/value_test.go index 9efc36f77..a3a4fba19 100644 --- a/src/reflect/value_test.go +++ b/src/reflect/value_test.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/base64" "fmt" + "internal/reflectlite" . "reflect" "runtime" "slices" @@ -992,3 +993,13 @@ func TestTypeAssertPanic(t *testing.T) { t.Fatalf("TypeAssert did not panic") }) } + +// Functions needed by all_test.go + +func IsRO(v Value) bool { + return reflectlite.IsRO(v.Value) +} + +func MakeRO(v Value) Value { + return Value{reflectlite.MakeRO(v.Value, true)} +}