@@ -169,13 +169,14 @@ func lastStmts(pass *analysis.Pass, stmts []ast.Stmt) []ast.Stmt {
169
169
s := stmts [len (stmts )- 1 ]
170
170
switch s := s .(type ) {
171
171
case * ast.IfStmt :
172
- res = append (res , lastStmts (pass , s .Body .List )... )
173
- if s .Else != nil {
174
- switch s := s .Else .(type ) {
172
+ var next * ast.IfStmt
173
+ for ; s != nil ; s , next = next , nil {
174
+ res = append (res , lastStmts (pass , s .Body .List )... )
175
+ switch e := s .Else .(type ) {
175
176
case * ast.BlockStmt :
176
- res = append (res , lastStmts (pass , s .List )... )
177
+ res = append (res , lastStmts (pass , e .List )... )
177
178
case * ast.IfStmt :
178
- res = append ( res , lastStmts ( pass , []ast. Stmt { s }) ... )
179
+ next = e
179
180
}
180
181
}
181
182
case * ast.ForStmt :
@@ -184,27 +185,21 @@ func lastStmts(pass *analysis.Pass, stmts []ast.Stmt) []ast.Stmt {
184
185
res = append (res , lastStmts (pass , s .Body .List )... )
185
186
case * ast.SwitchStmt :
186
187
for _ , c := range s .Body .List {
187
- c , ok := c .(* ast.CaseClause )
188
- if ! ok {
189
- continue
188
+ if c , ok := c .(* ast.CaseClause ); ok {
189
+ res = append (res , lastStmts (pass , c .Body )... )
190
190
}
191
- res = append (res , lastStmts (pass , c .Body )... )
192
191
}
193
192
case * ast.TypeSwitchStmt :
194
193
for _ , c := range s .Body .List {
195
- c , ok := c .(* ast.CaseClause )
196
- if ! ok {
197
- continue
194
+ if c , ok := c .(* ast.CaseClause ); ok {
195
+ res = append (res , lastStmts (pass , c .Body )... )
198
196
}
199
- res = append (res , lastStmts (pass , c .Body )... )
200
197
}
201
198
case * ast.SelectStmt :
202
199
for _ , c := range s .Body .List {
203
- c , ok := c .(* ast.CommClause )
204
- if ! ok {
205
- continue
200
+ if c , ok := c .(* ast.CommClause ); ok {
201
+ res = append (res , lastStmts (pass , c .Body )... )
206
202
}
207
- res = append (res , lastStmts (pass , c .Body )... )
208
203
}
209
204
case * ast.GoStmt :
210
205
res = append (res , litStmts (s .Call .Fun )... )
0 commit comments