.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / honnef.co / go / tools@v0.1.1 / staticcheck / testdata / src / CheckTypedNilInterface / i28241 / 28241.go
diff --git a/.config/coc/extensions/coc-go-data/tools/pkg/mod/honnef.co/go/tools@v0.1.1/staticcheck/testdata/src/CheckTypedNilInterface/i28241/28241.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/honnef.co/go/tools@v0.1.1/staticcheck/testdata/src/CheckTypedNilInterface/i28241/28241.go
new file mode 100644 (file)
index 0000000..f74d593
--- /dev/null
@@ -0,0 +1,39 @@
+package main
+
+import (
+       "fmt"
+       "reflect"
+)
+
+type Nil interface {
+       String() string
+}
+
+func MakeNil() Nil {
+       var n *NilStruct
+       return n
+}
+
+type NilStruct struct {
+       Data string
+}
+
+func (n *NilStruct) String() string {
+       return n.Data
+}
+
+func main() {
+       var n *NilStruct
+       fmt.Printf("%t %#v %s %t\n",
+               n == nil,
+               n,
+               reflect.ValueOf(n).Kind(),
+               reflect.ValueOf(n).IsNil())
+       n2 := MakeNil()
+       fmt.Printf("%t %#v %s %t\n",
+               n2 == nil, // want `this comparison is never true`
+               n2,
+               reflect.ValueOf(n2).Kind(),
+               reflect.ValueOf(n2).IsNil())
+       fmt.Println(n2.String())
+}