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).
This commit is contained in:
Damian Gryski
2026-06-30 09:26:55 -07:00
committed by Damian Gryski
parent 33ddee76db
commit 10224a4bf8
3 changed files with 22 additions and 12 deletions
+11 -4
View File
@@ -47,11 +47,18 @@ func (v Value) isExported() bool {
return v.flags&valueFlagExported != 0 return v.flags&valueFlagExported != 0
} }
func (v Value) IsRO() bool { func (v Value) isRO() bool {
return v.flags&(valueFlagRO) != 0 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 { if ro {
v.flags |= valueFlagRO v.flags |= valueFlagRO
} else { } else {
@@ -61,7 +68,7 @@ func (v Value) MakeRO(ro bool) Value {
} }
func (v Value) checkRO() { func (v Value) checkRO() {
if v.IsRO() { if v.isRO() {
panic("reflect: value is not settable") panic("reflect: value is not settable")
} }
} }
@@ -306,7 +313,7 @@ func (v Value) IsValid() bool {
} }
func (v Value) CanInterface() bool { func (v Value) CanInterface() bool {
return v.isExported() && !v.IsRO() return v.isExported() && !v.isRO()
} }
func (v Value) CanAddr() bool { func (v Value) CanAddr() bool {
-8
View File
@@ -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) { func TestConvert(t *testing.T) {
canConvert := map[[2]Type]bool{} canConvert := map[[2]Type]bool{}
all := map[Type]bool{} all := map[Type]bool{}
+11
View File
@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"internal/reflectlite"
. "reflect" . "reflect"
"runtime" "runtime"
"slices" "slices"
@@ -992,3 +993,13 @@ func TestTypeAssertPanic(t *testing.T) {
t.Fatalf("TypeAssert did not panic") 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)}
}