diff options
author | Ayke van Laethem <[email protected]> | 2021-03-24 23:13:15 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2021-03-28 19:28:55 +0200 |
commit | 2aa2e750b9e594f99012811c5a2def891dce69e1 (patch) | |
tree | 9180da2efecfd5db3477e866d102781621371e40 | |
parent | bcce296ca315d81633802183a8ba8658450f7ee3 (diff) | |
download | tinygo-2aa2e750b9e594f99012811c5a2def891dce69e1.tar.gz tinygo-2aa2e750b9e594f99012811c5a2def891dce69e1.zip |
reflect: implement Value.CanAddr
It is used in the crypto/sha512 test, for example. And it is very simple
to implement.
-rw-r--r-- | src/reflect/value.go | 2 | ||||
-rw-r--r-- | testdata/reflect.go | 5 | ||||
-rw-r--r-- | testdata/reflect.txt | 60 |
3 files changed, 35 insertions, 32 deletions
diff --git a/src/reflect/value.go b/src/reflect/value.go index a5f7278eb..28308f751 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -156,7 +156,7 @@ func (v Value) CanInterface() bool { } func (v Value) CanAddr() bool { - panic("unimplemented: (reflect.Value).CanAddr()") + return v.flags&(valueFlagIndirect) == valueFlagIndirect } func (v Value) Addr() Value { diff --git a/testdata/reflect.go b/testdata/reflect.go index 3d4b65fb6..2ddbe8dd7 100644 --- a/testdata/reflect.go +++ b/testdata/reflect.go @@ -315,7 +315,10 @@ func showValue(rv reflect.Value, indent string) { } print(indent+"reflect type: ", rt.Kind().String()) if rv.CanSet() { - print(" settable=", rv.CanSet()) + print(" settable=true") + } + if rv.CanAddr() { + print(" addrable=true") } if !rt.Comparable() { print(" comparable=false") diff --git a/testdata/reflect.txt b/testdata/reflect.txt index eeaa9c6f8..af9e7231f 100644 --- a/testdata/reflect.txt +++ b/testdata/reflect.txt @@ -72,63 +72,63 @@ reflect type: chan reflect type: ptr pointer: true int nil: false - reflect type: int settable=true + reflect type: int settable=true addrable=true int: 0 reflect type: ptr pointer: true interface nil: false - reflect type: interface settable=true + reflect type: interface settable=true addrable=true interface nil: true reflect type: ptr pointer: true int nil: false - reflect type: int settable=true + reflect type: int settable=true addrable=true int: 42 reflect type: ptr pointer: true int nil: false - reflect type: int settable=true + reflect type: int settable=true addrable=true int: 0 reflect type: slice comparable=false slice: uint8 3 3 pointer: true nil: false indexing: 0 - reflect type: uint8 settable=true + reflect type: uint8 settable=true addrable=true uint: 1 indexing: 1 - reflect type: uint8 settable=true + reflect type: uint8 settable=true addrable=true uint: 2 indexing: 2 - reflect type: uint8 settable=true + reflect type: uint8 settable=true addrable=true uint: 3 reflect type: slice comparable=false slice: uint8 2 5 pointer: true nil: false indexing: 0 - reflect type: uint8 settable=true + reflect type: uint8 settable=true addrable=true uint: 0 indexing: 1 - reflect type: uint8 settable=true + reflect type: uint8 settable=true addrable=true uint: 0 reflect type: slice comparable=false slice: int32 2 2 pointer: true nil: false indexing: 0 - reflect type: int32 settable=true + reflect type: int32 settable=true addrable=true int: 3 indexing: 1 - reflect type: int32 settable=true + reflect type: int32 settable=true addrable=true int: 5 reflect type: slice comparable=false slice: string 2 2 pointer: true nil: false indexing: 0 - reflect type: string settable=true + reflect type: string settable=true addrable=true string: xyz 3 reflect type: uint8 uint: 120 @@ -137,7 +137,7 @@ reflect type: slice comparable=false reflect type: uint8 uint: 122 indexing: 1 - reflect type: string settable=true + reflect type: string settable=true addrable=true string: Z 1 reflect type: uint8 uint: 90 @@ -154,53 +154,53 @@ reflect type: slice comparable=false pointer: true nil: false indexing: 0 - reflect type: float32 settable=true + reflect type: float32 settable=true addrable=true float: +1.000000e+000 indexing: 1 - reflect type: float32 settable=true + reflect type: float32 settable=true addrable=true float: +1.320000e+000 reflect type: slice comparable=false slice: float64 2 2 pointer: true nil: false indexing: 0 - reflect type: float64 settable=true + reflect type: float64 settable=true addrable=true float: +1.000000e+000 indexing: 1 - reflect type: float64 settable=true + reflect type: float64 settable=true addrable=true float: +1.640000e+000 reflect type: slice comparable=false slice: complex64 2 2 pointer: true nil: false indexing: 0 - reflect type: complex64 settable=true + reflect type: complex64 settable=true addrable=true complex: (+1.000000e+000+0.000000e+000i) indexing: 1 - reflect type: complex64 settable=true + reflect type: complex64 settable=true addrable=true complex: (+1.640000e+000+3.000000e-001i) reflect type: slice comparable=false slice: complex128 2 2 pointer: true nil: false indexing: 0 - reflect type: complex128 settable=true + reflect type: complex128 settable=true addrable=true complex: (+1.000000e+000+0.000000e+000i) indexing: 1 - reflect type: complex128 settable=true + reflect type: complex128 settable=true addrable=true complex: (+1.128000e+000+4.000000e-001i) reflect type: slice comparable=false slice: uint8 3 3 pointer: true nil: false indexing: 0 - reflect type: uint8 settable=true + reflect type: uint8 settable=true addrable=true uint: 5 indexing: 1 - reflect type: uint8 settable=true + reflect type: uint8 settable=true addrable=true uint: 3 indexing: 2 - reflect type: uint8 settable=true + reflect type: uint8 settable=true addrable=true uint: 11 reflect type: array array: 3 int64 24 @@ -290,10 +290,10 @@ reflect type: struct comparable=false pointer: true nil: false indexing: 0 - reflect type: uint8 + reflect type: uint8 addrable=true uint: 71 indexing: 1 - reflect type: uint8 + reflect type: uint8 addrable=true uint: 111 field: 4 Buf tag: @@ -303,23 +303,23 @@ reflect type: struct comparable=false pointer: true nil: false indexing: 0 - reflect type: uint8 settable=true + reflect type: uint8 settable=true addrable=true uint: 88 reflect type: ptr pointer: true struct nil: false - reflect type: struct settable=true + reflect type: struct settable=true addrable=true struct: 2 field: 0 next tag: description:"chain" embedded: false - reflect type: ptr + reflect type: ptr addrable=true pointer: false struct nil: true field: 1 foo tag: embedded: false - reflect type: int + reflect type: int addrable=true int: 42 sizes: |