mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
reflect: implement Value.Elem() for interface values
This commit is contained in:
committed by
Ron Evans
parent
d15e32fb89
commit
823c9c25cf
@@ -400,7 +400,14 @@ func (v Value) Elem() Value {
|
||||
value: ptr,
|
||||
flags: v.flags | valueFlagIndirect,
|
||||
}
|
||||
default: // not implemented: Interface
|
||||
case Interface:
|
||||
typecode, value := decomposeInterface(*(*interface{})(v.value))
|
||||
return Value{
|
||||
typecode: typecode,
|
||||
value: value,
|
||||
flags: v.flags &^ valueFlagIndirect,
|
||||
}
|
||||
default:
|
||||
panic(&ValueError{"Elem"})
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+5
@@ -120,6 +120,8 @@ func main() {
|
||||
&linkedList{
|
||||
foo: 42,
|
||||
},
|
||||
// interfaces
|
||||
[]interface{}{3, "str", -4 + 2.5i},
|
||||
} {
|
||||
showValue(reflect.ValueOf(v), "")
|
||||
}
|
||||
@@ -377,6 +379,9 @@ func showValue(rv reflect.Value, indent string) {
|
||||
case reflect.Interface:
|
||||
println(indent + " interface")
|
||||
println(indent+" nil:", rv.IsNil())
|
||||
if !rv.IsNil() {
|
||||
showValue(rv.Elem(), indent+" ")
|
||||
}
|
||||
case reflect.Map:
|
||||
println(indent + " map")
|
||||
println(indent+" nil:", rv.IsNil())
|
||||
|
||||
Vendored
+28
@@ -334,6 +334,34 @@ reflect type: ptr
|
||||
exported: false
|
||||
reflect type: int addrable=true
|
||||
int: 42
|
||||
reflect type: slice comparable=false
|
||||
slice: interface 3 3
|
||||
pointer: true
|
||||
nil: false
|
||||
indexing: 0
|
||||
reflect type: interface settable=true addrable=true
|
||||
interface
|
||||
nil: false
|
||||
reflect type: int
|
||||
int: 3
|
||||
indexing: 1
|
||||
reflect type: interface settable=true addrable=true
|
||||
interface
|
||||
nil: false
|
||||
reflect type: string
|
||||
string: str 3
|
||||
reflect type: uint8
|
||||
uint: 115
|
||||
reflect type: uint8
|
||||
uint: 116
|
||||
reflect type: uint8
|
||||
uint: 114
|
||||
indexing: 2
|
||||
reflect type: interface settable=true addrable=true
|
||||
interface
|
||||
nil: false
|
||||
reflect type: complex128
|
||||
complex: (-4.000000e+000+2.500000e+000i)
|
||||
reflect type: ptr
|
||||
pointer: true int8
|
||||
nil: false
|
||||
|
||||
Reference in New Issue
Block a user