mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
reflect: implement Set(nil), SetValue(nil) for PtrValue and MapValue
R=r CC=golang-dev https://golang.org/cl/823048
This commit is contained in:
parent
73374c93a6
commit
7295b61cdb
2 changed files with 48 additions and 2 deletions
|
|
@ -1038,12 +1038,22 @@ func (v *MapValue) Set(x *MapValue) {
|
|||
if !v.canSet {
|
||||
panic(cannotSet)
|
||||
}
|
||||
if x == nil {
|
||||
*(**uintptr)(v.addr) = nil
|
||||
return
|
||||
}
|
||||
typesMustMatch(v.typ, x.typ)
|
||||
*(*uintptr)(v.addr) = *(*uintptr)(x.addr)
|
||||
}
|
||||
|
||||
// Set sets v to the value x.
|
||||
func (v *MapValue) SetValue(x Value) { v.Set(x.(*MapValue)) }
|
||||
func (v *MapValue) SetValue(x Value) {
|
||||
if x == nil {
|
||||
v.Set(nil)
|
||||
return
|
||||
}
|
||||
v.Set(x.(*MapValue))
|
||||
}
|
||||
|
||||
// Get returns the uintptr value of v.
|
||||
// It is mainly useful for printing.
|
||||
|
|
@ -1146,6 +1156,10 @@ func (v *PtrValue) Get() uintptr { return *(*uintptr)(v.addr) }
|
|||
// Set assigns x to v.
|
||||
// The new value x must have the same type as v.
|
||||
func (v *PtrValue) Set(x *PtrValue) {
|
||||
if x == nil {
|
||||
*(**uintptr)(v.addr) = nil
|
||||
return
|
||||
}
|
||||
if !v.canSet {
|
||||
panic(cannotSet)
|
||||
}
|
||||
|
|
@ -1156,7 +1170,13 @@ func (v *PtrValue) Set(x *PtrValue) {
|
|||
}
|
||||
|
||||
// Set sets v to the value x.
|
||||
func (v *PtrValue) SetValue(x Value) { v.Set(x.(*PtrValue)) }
|
||||
func (v *PtrValue) SetValue(x Value) {
|
||||
if x == nil {
|
||||
v.Set(nil)
|
||||
return
|
||||
}
|
||||
v.Set(x.(*PtrValue))
|
||||
}
|
||||
|
||||
// PointTo changes v to point to x.
|
||||
func (v *PtrValue) PointTo(x Value) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue