Commit 64787e31 authored by Russ Cox's avatar Russ Cox

reflect: update CanAddr, CanSet documentation

CanAddr was wrong, out of date; CanSet was incomplete.

R=r
CC=golang-dev
https://golang.org/cl/4442066
parent 7412583e
...@@ -395,8 +395,7 @@ func (v Value) Bool() bool { ...@@ -395,8 +395,7 @@ func (v Value) Bool() bool {
// CanAddr returns true if the value's address can be obtained with Addr. // CanAddr returns true if the value's address can be obtained with Addr.
// Such values are called addressable. A value is addressable if it is // Such values are called addressable. A value is addressable if it is
// an element of a slice, an element of an addressable array, // an element of a slice, an element of an addressable array,
// a field of an addressable struct, the result of dereferencing a pointer, // a field of an addressable struct, or the result of dereferencing a pointer.
// or the result of a call to NewValue, MakeChan, MakeMap, or Zero.
// If CanAddr returns false, calling Addr will panic. // If CanAddr returns false, calling Addr will panic.
func (v Value) CanAddr() bool { func (v Value) CanAddr() bool {
iv := v.internal() iv := v.internal()
...@@ -404,8 +403,8 @@ func (v Value) CanAddr() bool { ...@@ -404,8 +403,8 @@ func (v Value) CanAddr() bool {
} }
// CanSet returns true if the value of v can be changed. // CanSet returns true if the value of v can be changed.
// Values obtained by the use of unexported struct fields // A Value can be changed only if it is addressable and was not
// can be read but not set. // obtained by the use of unexported struct fields.
// If CanSet returns false, calling Set or any type-specific // If CanSet returns false, calling Set or any type-specific
// setter (e.g., SetBool, SetInt64) will panic. // setter (e.g., SetBool, SetInt64) will panic.
func (v Value) CanSet() bool { func (v Value) CanSet() bool {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment