@@ -31,14 +31,16 @@ type TypeChecker interface {
3131}
3232
3333// NewTypeChecker returns a new TypeChecker with the provided checkFunc.
34- func NewTypeChecker (checkFunc func (pass * analysis.Pass , ident * ast.Ident , node ast.Node , prefix string )) TypeChecker {
34+ func NewTypeChecker (isTypeFunc func (pass * analysis.Pass , ident ast. Expr ) bool , checkFunc func ( pass * analysis. Pass , expr ast.Expr , node ast.Node , prefix string )) TypeChecker {
3535 return & typeChecker {
36- checkFunc : checkFunc ,
36+ isTypeFunc : isTypeFunc ,
37+ checkFunc : checkFunc ,
3738 }
3839}
3940
4041type typeChecker struct {
41- checkFunc func (pass * analysis.Pass , ident * ast.Ident , node ast.Node , prefix string )
42+ isTypeFunc func (pass * analysis.Pass , expr ast.Expr ) bool
43+ checkFunc func (pass * analysis.Pass , expr ast.Expr , node ast.Node , prefix string )
4244}
4345
4446// CheckNode checks the provided node for built-in types.
@@ -84,6 +86,11 @@ func (t *typeChecker) checkTypeSpec(pass *analysis.Pass, tSpec *ast.TypeSpec, no
8486}
8587
8688func (t * typeChecker ) checkTypeExpr (pass * analysis.Pass , typeExpr ast.Expr , node ast.Node , prefix string ) {
89+ if t .isTypeFunc (pass , typeExpr ) {
90+ t .checkFunc (pass , typeExpr , node , prefix )
91+ return
92+ }
93+
8794 switch typ := typeExpr .(type ) {
8895 case * ast.Ident :
8996 t .checkIdent (pass , typ , node , prefix )
@@ -100,12 +107,6 @@ func (t *typeChecker) checkTypeExpr(pass *analysis.Pass, typeExpr ast.Expr, node
100107// checkIdent calls the checkFunc with the ident, when we have hit a built-in type.
101108// If the ident is not a built in, we look at the underlying type until we hit a built-in type.
102109func (t * typeChecker ) checkIdent (pass * analysis.Pass , ident * ast.Ident , node ast.Node , prefix string ) {
103- if IsBasicType (pass , ident ) {
104- // We've hit a built-in type, no need to check further.
105- t .checkFunc (pass , ident , node , prefix )
106- return
107- }
108-
109110 tSpec , ok := LookupTypeSpec (pass , ident )
110111 if ! ok {
111112 return
0 commit comments