Hard
Engineer
SpeedRun
interfaces
nil
type-assertions
Go: The Nil Interface That Isn't Nil
+250 XP · 6 min · attempt 1
Problem
What does this Go program print?
type myErr struct{}
func (*myErr) Error() string { return "boom" }
func doWork() error {
var e *myErr = nil
return e
}
func main() {
err := doWork()
if err == nil {
fmt.Println("all good")
} else {
fmt.Println("got error")
}
}
Enter the exact output line.
Starter
// An interface value is nil only when BOTH its type and value are nil.
// Returning a typed nil pointer wraps it in an interface with a non-nil type.
Your answer
Playing as a guest — you'll be asked for a display name on submit. Log in to keep your XP across devices.