mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 03:27:48 +00:00
reflect: fix IsNil and Pointer for addressable pointer types
This commit is contained in:
committed by
Ron Evans
parent
7c758b0dfc
commit
0818a125c0
@@ -69,9 +69,14 @@ func (v Value) Kind() Kind {
|
||||
return v.Type().Kind()
|
||||
}
|
||||
|
||||
// IsNil returns whether the value is the nil value. It panics if the value Kind
|
||||
// is not a channel, map, pointer, function, slice, or interface.
|
||||
func (v Value) IsNil() bool {
|
||||
switch v.Kind() {
|
||||
case Chan, Map, Ptr:
|
||||
if v.isIndirect() {
|
||||
return *(*uintptr)(v.value) == 0
|
||||
}
|
||||
return v.value == nil
|
||||
case Func:
|
||||
if v.value == nil {
|
||||
@@ -96,9 +101,14 @@ func (v Value) IsNil() bool {
|
||||
}
|
||||
}
|
||||
|
||||
// Pointer returns the underlying pointer of the given value for the following
|
||||
// types: chan, map, pointer, unsafe.Pointer, slice, func.
|
||||
func (v Value) Pointer() uintptr {
|
||||
switch v.Kind() {
|
||||
case Chan, Map, Ptr, UnsafePointer:
|
||||
if v.isIndirect() {
|
||||
return *(*uintptr)(v.value)
|
||||
}
|
||||
return uintptr(v.value)
|
||||
case Slice:
|
||||
slice := (*SliceHeader)(v.value)
|
||||
|
||||
Reference in New Issue
Block a user