How to detect a reflect.Value of nil ?

471 views
Skip to first unread message

christoph...@gmail.com

unread,
Jun 1, 2023, 2:48:21 PM6/1/23
to golang-nuts
I have a method that receives a reflect.Value as input argument.

When the method is given the argument reflect.ValueOf(nil), the methods Type(), IsNil(), or IsZero() panic. For instance, when I call the method IsZero() I see the panic message "panic: reflect: call of reflect.Value.IsZero on zero Value " :)

Is there a way to detect that the method was given a reflect.ValueOf(nil) ?

Ian Lance Taylor

unread,
Jun 1, 2023, 2:52:51 PM6/1/23
to christoph...@gmail.com, golang-nuts

Rob Pike

unread,
Jun 1, 2023, 6:16:33 PM6/1/23
to Ian Lance Taylor, christoph...@gmail.com, golang-nuts
I find this situation unsatisfactory. See https://github.com/golang/go/issues/51649 for my suggested fix.

-rob


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXz7ydS%3DEvKRDxy2CYhxEvSvwKDyBPey%2BTuGVysQ_Ns9g%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages