-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reflect: Value docs and Value.Set panic message are not perfect #29701
Comments
Making this change at this point is sure to break some existing tests, and the benefit seems quite small. |
Agree. Another interesting find is the string representation of a zero package main
import "reflect"
import "fmt"
func main() {
var z reflect.Value // a zero Value value
var v = reflect.ValueOf(&z).Elem()
fmt.Println(v) // <invalid Value>
fmt.Println(z) // <invalid reflect.Value>
} |
It looks the docs of
|
Ah, in the last code example, the However, I think the docs may really need to be corrected. |
[edit]: sorry, my old understanding for the string representations was wrong. I also think the string representation of package main
import "reflect"
import "fmt"
func main() {
var z reflect.Value // a zero Value value
var v = reflect.ValueOf(&z).Elem()
fmt.Println(v) // <invalid Value>
fmt.Println(z) // <invalid reflect.Value>
fmt.Println(v.IsValid()) // true
var y = reflect.ValueOf(&v).Elem()
fmt.Println(y) // <reflect.Value Value>
} |
More: package main
import "reflect"
import "fmt"
func main() {
var z reflect.Value // a zero Value value
var w = reflect.ValueOf(&z)
var y = reflect.ValueOf(&w).Elem()
fmt.Println(y.Kind()) // struct
var v = w.Elem()
fmt.Println(v.Kind()) // struct
fmt.Println(v) // <invalid Value>
fmt.Println(v.IsValid()) // true
// The two lines should be both panic or both not.
v.Set(v) // ok
v.Set(z) // panic: reflect: call of reflect.Value.Set on zero Value
} [edit]: sorry, the behavior of the program is okay. But the error message is misleading. |
Sorry, updated my last two comments. |
closed for some misunderstanding on printing |
What version of Go are you using (
go version
)?go version go1.12beta2 linux/amd64
What did you do?
What did you expect to see?
<invalid value>
is better than<invalid reflect.Value>
.All
reflect.Value
values are valid. It is just that the values represented by somereflect.Value
values are invalid.[update]: the intention of this issue has changed. Now it requests:
reflect.Value
to2. use a better panic message for invalid(Not right)reflect.Value.Set
argumentsee #29701 (comment) for details.=======
The design for the string representation of a validIt is not weird when you get it.reflect.Value
which represents anotherreflect.Value
value is like the form[the-type-of-the-value-represented-by-the-Value-represented-by-the-Value Value]
is a little weird, but it is not a big problem I think.The text was updated successfully, but these errors were encountered: