3 ms·
Actually, the issue mentioned by the OP is covered here: http://golang.org/doc/faq#nil_error http://golang.org/doc/faq#nil_error Basically, if you pass 'nil'
by falcolas 11y ago
Actually, the issue mentioned by the OP is covered here:
http://golang.org/doc/faq#nil_error http://golang.org/doc/faq#nil_error
Basically, if you pass 'nil' of one type into an argument which accepts an interface of another type, the nil is no longer nil, but an interface wrapper around a nil (which is not nil).
So:
var buf *bufio.Reader // a nil value
if this is passed into a function with a signature of
func foo(buf io.Reader)
then when in function foo:
foo(buf) // valid, and buf is nil here
//inside foo:
if buf != nil { // but buf is not nil here, so this is true
buf.Read() // Panics because nil has no function Read.
- pcwalton 11y agoThe post you were replying to was talking about whether the behavior is intuitive, not whether it is documented.
- Redoubts 11y agoI'm confused, how is that different from https://play.golang.org/p/rup5cqapEU https://play.golang.org/p/rup5cqapEU where calling on the nil value of T seems to work.