feat(reflect): add Indirect function
Implements reflect.Indirect function to support pointer dereferencing. This function returns the value that a pointer points to, or returns the value unchanged if it's not a pointer. Fixes #1354 Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <luoliwoshang@users.noreply.github.com>
This commit is contained in:
@@ -1759,6 +1759,16 @@ func ValueOf(i any) Value {
|
||||
return unpackEface(i)
|
||||
}
|
||||
|
||||
// Indirect returns the value that v points to.
|
||||
// If v is a nil pointer, Indirect returns a zero Value.
|
||||
// If v is not a pointer, Indirect returns v.
|
||||
func Indirect(v Value) Value {
|
||||
if v.Kind() != Pointer {
|
||||
return v
|
||||
}
|
||||
return v.Elem()
|
||||
}
|
||||
|
||||
// arrayAt returns the i-th element of p,
|
||||
// an array whose elements are eltSize bytes wide.
|
||||
// The array pointed at by p must have at least i+1 elements:
|
||||
|
||||
Reference in New Issue
Block a user