Last active
March 15, 2023 08:37
-
-
Save mvo5/0586ab732a3fcb8547145586d82fd409 to your computer and use it in GitHub Desktop.
Go can have weird behavior for nil - this illustrates one pitfal.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
) | |
func foo() error { | |
err := &os.SyscallError{} | |
err = nil | |
return err | |
} | |
func main() { | |
if err := foo(); err != nil { | |
fmt.Printf("err is: %[1]p %[1]v (%[1]T)\n", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment