mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-13 23:43:40 +00:00
reflect: fix Addr() indirect value/flags and add tests.
This commit is contained in:
@@ -223,7 +223,7 @@ func (v Value) Addr() Value {
|
|||||||
|
|
||||||
return Value{
|
return Value{
|
||||||
typecode: pointerTo(v.typecode),
|
typecode: pointerTo(v.typecode),
|
||||||
value: unsafe.Pointer(&v.value),
|
value: v.value,
|
||||||
flags: v.flags ^ valueFlagIndirect,
|
flags: v.flags ^ valueFlagIndirect,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -266,6 +266,31 @@ func TestNamedTypes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addrDecode(body interface{}) {
|
||||||
|
vbody := ValueOf(body)
|
||||||
|
ptr := vbody.Elem()
|
||||||
|
pptr := ptr.Addr()
|
||||||
|
addrSetInt(pptr.Interface())
|
||||||
|
}
|
||||||
|
|
||||||
|
func addrSetInt(intf interface{}) {
|
||||||
|
ptr := intf.(*uint64)
|
||||||
|
*ptr = 112358
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddr(t *testing.T) {
|
||||||
|
var n uint64
|
||||||
|
addrDecode(&n)
|
||||||
|
if n != 112358 {
|
||||||
|
t.Errorf("Failed to set t=112358, got %v", n)
|
||||||
|
}
|
||||||
|
|
||||||
|
v := ValueOf(&n)
|
||||||
|
if got, want := v.Elem().Addr().CanAddr(), false; got != want {
|
||||||
|
t.Errorf("Elem.Addr.CanAddr=%v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func equal[T comparable](a, b []T) bool {
|
func equal[T comparable](a, b []T) bool {
|
||||||
if len(a) != len(b) {
|
if len(a) != len(b) {
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user