You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@mvdan This is quite non-intuitive.
What is the decisive reason for reflect.New that creates a pointer to the value?
What is the correct way to check the newly created (actual) value by reflect.New is a zero value?
See the docs at https://golang.org/pkg/reflect/#New. It works exactly like new, and has been like that for years, so we can't change it even if we wanted to.
If you want to check if the data behind the pointer is zero, do ptr.Elem().IsZero(). You should check the documentation to see why that works.
In the future, please try asking questions about reflect in the forums or Slack before filing bugs. The package takes a while to master, so most problems tend to not be bugs in Go itself.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/F_XFkJRADDL
What did you expect to see?
The expected output is
true
becausereflect.New
creates a zero valueWhat did you see instead?
Actual output is
false
.The text was updated successfully, but these errors were encountered: