Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / honnef.co / go / tools@v0.0.1-2020.1.5 / staticcheck / testdata / src / CheckMaybeNil / CheckMaybeNil.go
1 package pkg
2
3 import "os"
4
5 func fn1(x *int) {
6         _ = *x // want `possible nil pointer dereference`
7         if x != nil {
8                 return
9         }
10 }
11
12 func fn2(x *int) {
13         if x == nil {
14                 println("we should return")
15         }
16         _ = *x // want `possible nil pointer dereference`
17 }
18
19 func fn3(x *int) {
20         if x != nil {
21                 _ = *x
22         }
23 }
24
25 func fn4(x *int) {
26         if x == nil {
27                 x = gen()
28         }
29         _ = *x
30 }
31
32 func fn5(x *int) {
33         if x == nil {
34                 x = gen()
35         }
36         _ = *x // want `possible nil pointer dereference`
37         if x == nil {
38                 println("we should return")
39         }
40 }
41
42 func fn6() {
43         x := new(int)
44         if x == nil {
45                 println("we should return")
46         }
47         // x can't be nil
48         _ = *x
49 }
50
51 func fn7() {
52         var x int
53         y := &x
54         if y == nil {
55                 println("we should return")
56         }
57         // y can't be nil
58         _ = *y
59 }
60
61 func fn8(x *int) {
62         if x == nil {
63                 return
64         }
65         // x can't be nil
66         _ = *x
67 }
68
69 func fn9(x *int) {
70         if x != nil {
71                 return
72         }
73         // TODO(dh): not currently supported
74         _ = *x
75 }
76
77 func gen() *int { return nil }
78
79 func die1(b bool) {
80         if b {
81                 println("yay")
82                 os.Exit(0)
83         } else {
84                 println("nay")
85                 os.Exit(1)
86         }
87 }
88
89 func die2(b bool) {
90         if b {
91                 println("yay")
92                 os.Exit(0)
93         }
94 }
95
96 func fn10(x *int) {
97         if x == nil {
98                 die1(true)
99         }
100         _ = *x
101 }
102
103 func fn11(x *int) {
104         if x == nil {
105                 die2(true)
106         }
107         _ = *x // want `possible nil pointer dereference`
108 }