reflect: add SetLen()

This commit is contained in:
Damian Gryski
2023-02-28 09:54:39 -08:00
committed by Damian Gryski
parent e4ef6f85ac
commit 960a0b79bf
2 changed files with 24 additions and 3 deletions
+9 -1
View File
@@ -952,7 +952,15 @@ func (v Value) SetCap(n int) {
}
func (v Value) SetLen(n int) {
panic("unimplemented: (reflect.Value).SetLen()")
if v.typecode.Kind() != Slice {
panic(&ValueError{"reflect.Value.SetLen", v.Kind()})
}
hdr := (*sliceHeader)(v.value)
if int(uintptr(n)) != n || uintptr(n) > hdr.cap {
panic("reflect.Value.SetLen: slice length out of range")
}
hdr.len = uintptr(n)
}
func (v Value) checkAddressable() {