Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.

Commit fe09255

Browse files
committed
fix if
1 parent 1d21e27 commit fe09255

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

passes/bodyclose/bodyclose.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
Doc = "bodyclose checks whether HTTP response body is closed successfully"
2727

2828
nethttpPath = "net/http"
29+
closeMethod = closeMethod
2930
)
3031

3132
type runner struct {
@@ -70,7 +71,7 @@ func (r *runner) run(pass *analysis.Pass) (interface{}, error) {
7071
bodyItrf := bodyNamed.Underlying().(*types.Interface)
7172
for i := 0; i < bodyItrf.NumMethods(); i++ {
7273
bmthd := bodyItrf.Method(i)
73-
if bmthd.Id() == "Close" {
74+
if bmthd.Id() == closeMethod {
7475
r.closeMthd = bmthd
7576
}
7677
}
@@ -156,15 +157,14 @@ func (r *runner) isopen(b *ssa.BasicBlock, i int) bool {
156157
}
157158
vrefs := *v.Referrers()
158159
for _, vref := range vrefs {
159-
switch vref := vref.(type) {
160-
case *ssa.UnOp:
160+
if vref, ok := vref.(*ssa.UnOp); ok {
161161
vrefs := *vref.Referrers()
162162
if len(vrefs) == 0 {
163163
return true
164164
}
165165
for _, vref := range vrefs {
166166
if c, ok := vref.(*ssa.Call); ok {
167-
if c.Call.Method.Name() == "Close" {
167+
if c.Call.Method.Name() == closeMethod {
168168
return !called
169169
}
170170
}
@@ -270,10 +270,8 @@ func (r *runner) isCloseCall(ccall ssa.Instruction) bool {
270270
closeMtd := ccall.Type().Underlying().(*types.Interface).Method(0)
271271
crs := *ccall.Referrers()
272272
for _, cs := range crs {
273-
switch cs := cs.(type) {
274-
case *ssa.Defer:
275-
switch val := cs.Common().Value.(type) {
276-
case *ssa.Function:
273+
if cs, ok := cs.(*ssa.Defer); ok {
274+
if val, ok := cs.Common().Value.(*ssa.Function); ok {
277275
for _, b := range val.Blocks {
278276
for _, instr := range b.Instrs {
279277
if c, ok := instr.(*ssa.Call); ok {

0 commit comments

Comments
 (0)