1. 10
  1.  

  2. 3

    But wait, it gets even more confusing yet again! Sometimes the Go compiler won’t turn an untyped nil into a typed nil.

    I feel like the author doesn’t really make the distinction between a nil value and an interface wrapping a nil value, and this is where all the confusion stems from.

    I solved a similar same issue not by using reflection but by writing boilerplate code to assert to every type that my interfaces were being implemented by (from my own code at least) and checking those values for nil. Granted this might not work as well if you don’t control all types and interfaces that need this nil check or if you use interface{} for your types.

    1. 4

      Indeed; this post is more confusing than it ought to be because the author hasn’t actually understood it deeply yet (as evidenced by “I think the way this works is that anything typed as an interface also has a real underlying type”).

      The FAQ covers this.

      1. 2

        Great, I was actually looking for this bit to link to, but failed to find it. For some reason I didn’t realize it was right there in the FAQ. :D

        Thank you.