Skip to content

Instantly share code, notes, and snippets.

@7c00
Created October 12, 2017 11:03
Show Gist options
  • Save 7c00/ca4c0d37e889868572e9362d4f6697de to your computer and use it in GitHub Desktop.
Save 7c00/ca4c0d37e889868572e9362d4f6697de to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
"reflect"
)
func main() {
if len(os.Args) >= 2 && os.Args[1] == "-p" {
// with -p
t := reflect.TypeOf((*error)(nil)).Elem()
fmt.Println(t.Kind())
return
}
t := reflect.TypeOf((error)(nil))
fmt.Println(t.Kind())
}
$ go run niltype.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xa0 pc=0x47b7d7]
goroutine 1 [running]:
main.main()
...(omitted).../niltype.go:18 +0x177
exit status 2
$ go run niltype.go -p
interface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment