On Wednesday, March 16, 2022 at 12:29:07 PM UTC-7 axel.wa...@googlemail.com 
wrote:

> On Wed, Mar 16, 2022 at 7:02 PM Alex Besogonov <alex.be...@gmail.com> 
> wrote:
>
>> Nope. Your solution doesn't work either: 
>> https://go.dev/play/p/DSik2kJ-gg4 (it doesn't crash, just falsely 
>> returns 'false').
>>
> That's your original code. I assume, though, you are trying to demonstrate 
> that this doesn't return `true` when passed a nil-slice/func/chan/map. 
> That's by design - the function does what it is designed to do, check if an 
> interface value contains a nil-pointer. If you want something else, write a 
> different function.
>
I don't believe that's true. The function is passed an interface (Tester) 
that has a nil pointer part but a non-nil type. That type also happens to 
be a struct with an embedded pointer to another struct that implements the 
interface.

Here's a simplified version of the real code: 
https://go.dev/play/p/8LfgIGhd8GR - it compiles without any issues.
  

> What I'm trying to check is pretty straightforward: do I get the nil value 
>> passed to a function.
>>
>
> The way to check that is `return v == nil`. What you seem to be interested 
> in is "I want to write a function which checks if the dynamic type of a 
> function is a pointer, slice, channel, function or map type and if so, 
> returns if the dynamic value is nil". You can write that easily enough 
> <https://go.dev/play/p/X_pHOrxxago>.
>
Except that you can not. In my case I have an interface that has the nil 
data part, and the program crashes because the reflect code doesn't know 
that I'm accessing the interface.

You can check my example, if you remove the nil check and use non-nil 
parameters, it would work just fine.

-- 
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/70a80a76-44b5-4af3-9eb5-2d8794e4d3c4n%40googlegroups.com.

Reply via email to