Skip to content

Commit

Permalink
refactor: extract isExprHasType
Browse files Browse the repository at this point in the history
  • Loading branch information
kulti committed Dec 15, 2021
1 parent 6eac340 commit 95051f0
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,7 @@ func checkFunc(pass *analysis.Pass, reports *reports, funcDecl funcDecl, opts ch

func searchFuncParam(pass *analysis.Pass, f funcDecl, p types.Type) (*ast.Field, int, bool) {
for i, f := range f.Type.Params.List {
typeInfo, ok := pass.TypesInfo.Types[f.Type]
if !ok {
continue
}

if types.Identical(typeInfo.Type, p) {
if isExprHasType(pass, f.Type, p) {
return f, i, true
}
}
Expand Down Expand Up @@ -414,3 +409,13 @@ func isSelectorCall(pass *analysis.Pass, selExpr *ast.SelectorExpr, callObj type

return sel.Obj() == callObj
}

// isExprHasType returns true if expr has expected type.
func isExprHasType(pass *analysis.Pass, expr ast.Expr, expType types.Type) bool {
typeInfo, ok := pass.TypesInfo.Types[expr]
if !ok {
return false
}

return types.Identical(typeInfo.Type, expType)
}

0 comments on commit 95051f0

Please sign in to comment.