diff options
author | Damian Gryski <[email protected]> | 2023-03-21 11:11:19 -0700 |
---|---|---|
committer | Ayke <[email protected]> | 2023-03-21 20:53:37 +0100 |
commit | 17f5fb1071afa78ca41220a197098506377b2396 (patch) | |
tree | 9787f51d5ea0aae444388c11e2630beacf1768f3 | |
parent | 4d43df75d5d32d5809dde49e6b851f5bdd565855 (diff) | |
download | tinygo-17f5fb1071afa78ca41220a197098506377b2396.tar.gz tinygo-17f5fb1071afa78ca41220a197098506377b2396.zip |
reflect; SetLen() requires an addressable value
-rw-r--r-- | src/reflect/value.go | 2 | ||||
-rw-r--r-- | src/reflect/value_test.go | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/src/reflect/value.go b/src/reflect/value.go index f63a503ec..a5f6782f7 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -999,7 +999,7 @@ func (v Value) SetLen(n int) { if v.typecode.Kind() != Slice { panic(&ValueError{Method: "reflect.Value.SetLen", Kind: v.Kind()}) } - + v.checkAddressable() hdr := (*sliceHeader)(v.value) if int(uintptr(n)) != n || uintptr(n) > hdr.cap { panic("reflect.Value.SetLen: slice length out of range") diff --git a/src/reflect/value_test.go b/src/reflect/value_test.go index 148e8c81f..1074a1668 100644 --- a/src/reflect/value_test.go +++ b/src/reflect/value_test.go @@ -180,6 +180,8 @@ func TestSlice(t *testing.T) { } // should be equivalent to s28 now, except for the capacity which doesn't change + + s268ref = ValueOf(&s268).Elem() s268ref.SetLen(6) 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()) |