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's FieldByName does not really return a zero value if field does not exist in a struct #43688
Comments
it returns a zero value closing as working as intended |
To check for the zero value of |
Why is then language "zero Value" and not "invalid Value"? So language could be:
|
The reflect documentation consistently refers to the "zero Value". For example, the docs for |
It also says: "Most functions and methods never return an invalid Value." :-) So both terminologies are used. And I think one would be less confusing than the other. Especially because "zero" is used also in other contexts. I understand that now that I know this I can find it and understand what it means. But both me and my co-reviewer at my company both thought that here there should be |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Tested on go 1.15.6: https://play.golang.org/p/w-_XNjx9m34
What operating system and processor architecture are you using (
go env
)?Reproducible on Go Playground.
What did you do?
I tried to get a field which does not exist of a struct using
reflect
.What did you expect to see?
FieldByName
documentation says:So I would expect that I can call
IsZero
on the returned value.What did you see instead?
My program panics. Reproduction:
Instead, I have to use
IsValid
:The text was updated successfully, but these errors were encountered: