Comment

Comment by im-a-baby

Yea, the issue is that nil's in Go are typed. So `err == nil` is checking err against error's nil value, but the value stored in err is *MyError's nil value.

    package main
    
    import "fmt"
    
    type MyError struct{}
    
    func (m *MyError) Error() string {
        return ""
    }
    
    func main() {
        var err error = nil
        var myErr *MyError = nil

        fmt.Println(err == myErr) // this is false
    }
parent im-a-baby 4 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton