diff options
| author | Taras Madan <tarasmadan@google.com> | 2023-02-22 22:16:50 +0100 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2023-02-24 12:47:23 +0100 |
| commit | 4165372ec8fd142475a4e35fd0cf4f8042132208 (patch) | |
| tree | 21cd62211b4dd80bee469054c5b65db77342333c /vendor/github.com/timakin | |
| parent | 2b3ed821a493b8936c8bacfa6f8b4f1c90a00855 (diff) | |
dependencies: update
set go min requirements to 1.19
update dependencies
update vendor
Diffstat (limited to 'vendor/github.com/timakin')
| -rw-r--r-- | vendor/github.com/timakin/bodyclose/passes/bodyclose/bodyclose.go | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/vendor/github.com/timakin/bodyclose/passes/bodyclose/bodyclose.go b/vendor/github.com/timakin/bodyclose/passes/bodyclose/bodyclose.go index a7ff30b49..acf7a0393 100644 --- a/vendor/github.com/timakin/bodyclose/passes/bodyclose/bodyclose.go +++ b/vendor/github.com/timakin/bodyclose/passes/bodyclose/bodyclose.go @@ -64,6 +64,8 @@ func (r runner) run(pass *analysis.Pass) (interface{}, error) { field := resStruct.Field(i) if field.Id() == "Body" { r.bodyObj = field + + break } } if r.bodyObj == nil { @@ -75,21 +77,20 @@ func (r runner) run(pass *analysis.Pass) (interface{}, error) { bmthd := bodyItrf.Method(i) if bmthd.Id() == closeMethod { r.closeMthd = bmthd + + break } } r.skipFile = map[*ast.File]bool{} +FuncLoop: for _, f := range funcs { // skip if the function is just referenced - var isreffunc bool for i := 0; i < f.Signature.Results().Len(); i++ { if f.Signature.Results().At(i).Type().String() == r.resTyp.String() { - isreffunc = true + continue FuncLoop } } - if isreffunc { - continue - } for _, b := range f.Blocks { for i := range b.Instrs { @@ -144,11 +145,26 @@ func (r *runner) isopen(b *ssa.BasicBlock, i int) bool { } } - case *ssa.Call: // Indirect function call - if f, ok := resRef.Call.Value.(*ssa.Function); ok { + case *ssa.Call, *ssa.Defer: // Indirect function call + // Hacky way to extract CommonCall + var call ssa.CallCommon + switch rr := resRef.(type) { + case *ssa.Call: + call = rr.Call + case *ssa.Defer: + call = rr.Call + } + + if f, ok := call.Value.(*ssa.Function); ok { for _, b := range f.Blocks { - for i := range b.Instrs { - return r.isopen(b, i) + for i, bi := range b.Instrs { + if r.isCloseCall(bi) { + return false + } + + if r.isopen(b, i) { + return true + } } } } |
