Skip to content

Commit eee2466

Browse files
committed
check cast result
1 parent 836c507 commit eee2466

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

analyzer/analyzer.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package analyzer
22

33
import (
4+
"errors"
45
"flag"
56
"go/ast"
67
"go/types"
@@ -30,7 +31,10 @@ func run(pass *analysis.Pass) (interface{}, error) {
3031
reportErrorInDefer := pass.Analyzer.Flags.Lookup(FlagReportErrorInDefer).Value.String() == "true"
3132
errorType := types.Universe.Lookup("error").Type()
3233

33-
inspector := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
34+
inspector, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
35+
if !ok {
36+
return nil, errors.New("failed to get inspector")
37+
}
3438

3539
// only filter function defintions
3640
nodeFilter := []ast.Node{
@@ -87,7 +91,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
8791
}
8892
})
8993

90-
return nil, nil
94+
return nil, nil // nolint:nilnil
9195
}
9296

9397
func findDeferWithVariableAssignment(body *ast.BlockStmt, info *types.Info, variable types.Object) bool {

0 commit comments

Comments
 (0)