On Wed, Mar 16, 2022 at 6:21 PM Alex Besogonov <alex.besogo...@gmail.com>
wrote:

> I'm trying to solve the eternal "interface == nil" problem and I can't
> find a solution in this case: https://go.dev/play/p/DSik2kJ-gg4
>

ISTM that you are discovering why this check just is not an interesting
check to make in the first place.

There is no meaning you can assign to "is the dynamic value of a non-nil
interface nil", as `nil` might not even be a valid value for its dynamic
type. It's also not a *helpful* check, because even non-nil pointers can
cause a panic, if you call an associated method on them.

You *can* write a check to see if a value contains a pointer relatively
easily using reflect:
https://go.dev/play/p/dDHp7KnoHHS
But it's not a very useful check, unless you specifically want to work
further with the pointer using reflect (e.g. how json.Unmarshal stores a
value in a pointer).


>
> It looks like casting to the base pointer type confuses the reflection
> package. Is there a way to solve this?
>
> PS: PLEASE do add "nilptr" to the language proper.
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/469b88b2-6d64-4bcd-8b92-18f9781c4fd3n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/469b88b2-6d64-4bcd-8b92-18f9781c4fd3n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfHEL8O%2BituCk6NvCWg7Kg6KL%2BJLU6oK-7mGaGteMrj%3DQg%40mail.gmail.com.

Reply via email to