I'm trying to wrap my head around this playground https://play.golang.org/p/CJmDivZGrZM
I don't understand why this if statement claims err != nil
if err := baz(); err == nil {
fmt.Println("3. No error", err == nil)
} else {
fmt.Println("3. Error, err != nil ", err, err == nil)
}
The output from that if/else is "3. Error, err != nil false", so print sees it's nil, but the comparison doesn't. If I try to access err.Error() is it panicking and crashing.
My two questions are:
- Why is the comparison not seeing err as nil?
- Why isn't it caught by the compiler?