Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201105173854-bc9fc8d8c4bc / go / analysis / passes / ctrlflow / testdata / src / a / a.go
1 package a
2
3 // This file tests facts produced by ctrlflow.
4
5 import (
6         "log"
7         "os"
8         "runtime"
9         "syscall"
10         "testing"
11
12         "lib"
13 )
14
15 var cond bool
16
17 func a() { // want a:"noReturn"
18         if cond {
19                 b()
20         } else {
21                 for {
22                 }
23         }
24 }
25
26 func b() { // want b:"noReturn"
27         select {}
28 }
29
30 func f(x int) { // no fact here
31         switch x {
32         case 0:
33                 os.Exit(0)
34         case 1:
35                 panic(0)
36         }
37         // default case returns
38 }
39
40 type T int
41
42 func (T) method1() { // want method1:"noReturn"
43         a()
44 }
45
46 func (T) method2() { // (may return)
47         if cond {
48                 a()
49         }
50 }
51
52 // Checking for the noreturn fact associated with F ensures that
53 // ctrlflow proved each of the listed functions was "noReturn".
54 //
55 func standardFunctions(x int) { // want standardFunctions:"noReturn"
56         t := new(testing.T)
57         switch x {
58         case 0:
59                 t.FailNow()
60         case 1:
61                 t.Fatal()
62         case 2:
63                 t.Fatalf("")
64         case 3:
65                 t.Skip()
66         case 4:
67                 t.SkipNow()
68         case 5:
69                 t.Skipf("")
70         case 6:
71                 log.Fatal()
72         case 7:
73                 log.Fatalf("")
74         case 8:
75                 log.Fatalln()
76         case 9:
77                 os.Exit(0)
78         case 10:
79                 syscall.Exit(0)
80         case 11:
81                 runtime.Goexit()
82         case 12:
83                 log.Panic()
84         case 13:
85                 log.Panicln()
86         case 14:
87                 log.Panicf("")
88         default:
89                 panic(0)
90         }
91 }
92
93 // False positives are possible.
94 // This function is marked noReturn but in fact returns.
95 //
96 func spurious() { // want spurious:"noReturn"
97         defer func() { recover() }()
98         panic(nil)
99 }
100
101 func noBody()
102
103 func g() {
104         lib.CanReturn()
105 }
106
107 func h() { // want h:"noReturn"
108         lib.NoReturn()
109 }