Skip to content

Instantly share code, notes, and snippets.

@tucnak
Created October 28, 2015 09:06
Show Gist options
  • Save tucnak/eccdb53e7884084f5674 to your computer and use it in GitHub Desktop.
Save tucnak/eccdb53e7884084f5674 to your computer and use it in GitHub Desktop.
Nil errors are not always nil :)
package main
import "fmt"
type MagicError struct{}
func (MagicError) Error() string {
return "[Magic]"
}
func Generate() *MagicError {
return nil
}
func Test() error {
return Generate()
}
func main() {
if Test() != nil {
fmt.Println("Hello, Mr. Pike!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment