reflect: allow PtrValue.PointTo(nil)

(Argument: For any *PtrValue p, it should
always be possible to do: p.PointTo(p.Elem()),
even if p.Elem() is nil.)

Fixes #1028.

R=rsc
CC=golang-dev, r
https://golang.org/cl/1938044
This commit is contained in:
Robert Griesemer 2010-08-17 15:12:28 -07:00
parent 660ce1425f
commit a48b35e961
2 changed files with 12 additions and 0 deletions

View file

@ -1058,7 +1058,12 @@ func (v *PtrValue) SetValue(x Value) {
}
// PointTo changes v to point to x.
// If x is a nil Value, PointTo sets v to nil.
func (v *PtrValue) PointTo(x Value) {
if x == nil {
*(**uintptr)(v.addr) = nil
return
}
if !x.CanSet() {
panic("cannot set x; cannot point to x")
}