mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 11:33:59 +00:00
reflect; SetLen() requires an addressable value
This commit is contained in:
@@ -999,7 +999,7 @@ func (v Value) SetLen(n int) {
|
|||||||
if v.typecode.Kind() != Slice {
|
if v.typecode.Kind() != Slice {
|
||||||
panic(&ValueError{Method: "reflect.Value.SetLen", Kind: v.Kind()})
|
panic(&ValueError{Method: "reflect.Value.SetLen", Kind: v.Kind()})
|
||||||
}
|
}
|
||||||
|
v.checkAddressable()
|
||||||
hdr := (*sliceHeader)(v.value)
|
hdr := (*sliceHeader)(v.value)
|
||||||
if int(uintptr(n)) != n || uintptr(n) > hdr.cap {
|
if int(uintptr(n)) != n || uintptr(n) > hdr.cap {
|
||||||
panic("reflect.Value.SetLen: slice length out of range")
|
panic("reflect.Value.SetLen: slice length out of range")
|
||||||
|
|||||||
@@ -180,6 +180,8 @@ func TestSlice(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// should be equivalent to s28 now, except for the capacity which doesn't change
|
// should be equivalent to s28 now, except for the capacity which doesn't change
|
||||||
|
|
||||||
|
s268ref = ValueOf(&s268).Elem()
|
||||||
s268ref.SetLen(6)
|
s268ref.SetLen(6)
|
||||||
if len(s28) != s268ref.Len() || cap(s268) != s268ref.Cap() {
|
if len(s28) != s268ref.Len() || cap(s268) != s268ref.Cap() {
|
||||||
t.Errorf("SetLen: len(s268)=%d s268ref.Len()=%d cap(s268)=%d s268ref.Cap()=%d\n", len(s28), s268ref.Len(), cap(s268), s268ref.Cap())
|
t.Errorf("SetLen: len(s268)=%d s268ref.Len()=%d cap(s268)=%d s268ref.Cap()=%d\n", len(s28), s268ref.Len(), cap(s268), s268ref.Cap())
|
||||||
|
|||||||
Reference in New Issue
Block a user