Source file
test/defererrcheck.go
1
2
3
4
5
6
7
8
9 package main
10
11 import "fmt"
12
13 var glob = 3
14
15 func f1() {
16
17 for i := 0; i < 10; i++ {
18 fmt.Println("loop")
19 }
20 defer func() {
21 fmt.Println("defer")
22 }()
23 }
24
25 func f2() {
26 for {
27 defer func() {
28 fmt.Println("defer1")
29 }()
30 if glob > 2 {
31 break
32 }
33 }
34 defer func() {
35 fmt.Println("defer2")
36 }()
37 }
38
39 func f3() {
40 defer func() {
41 fmt.Println("defer2")
42 }()
43 for {
44 defer func() {
45 fmt.Println("defer1")
46 }()
47 if glob > 2 {
48 break
49 }
50 }
51 }
52
53 func f4() {
54 defer func() {
55 fmt.Println("defer")
56 }()
57 label:
58 fmt.Println("goto loop")
59 if glob > 2 {
60 goto label
61 }
62 }
63
64 func f5() {
65 label:
66 fmt.Println("goto loop")
67 defer func() {
68 fmt.Println("defer")
69 }()
70 if glob > 2 {
71 goto label
72 }
73 }
74
75 func f6() {
76 label:
77 fmt.Println("goto loop")
78 if glob > 2 {
79 goto label
80 }
81
82
83 defer func() {
84 fmt.Println("defer")
85 }()
86 }
87
88
89
90 func f7() {
91 defer println(1)
92 defer println(1)
93 defer println(1)
94 defer println(1)
95
96 switch glob {
97 case 1:
98 return
99 case 2:
100 return
101 case 3:
102 return
103 }
104 }
105
106 func f8() {
107 defer println(1)
108 defer println(1)
109 defer println(1)
110 defer println(1)
111
112 switch glob {
113 case 1:
114 return
115 case 2:
116 return
117 case 3:
118 return
119 case 4:
120 return
121 }
122 }
123
124 func f9() {
125 defer println(1)
126 defer println(1)
127 defer println(1)
128 defer println(1)
129
130 switch glob {
131 case 1:
132 return
133 case 2:
134 return
135 case 3:
136 return
137 case 4:
138 panic("")
139 }
140 }
141
View as plain text