@@ -34,10 +34,10 @@ var allowedErrors = []struct {
34
34
{err : "io.EOF" , fun : "(*bytes.Reader).ReadRune" },
35
35
{err : "io.EOF" , fun : "(*bytes.Reader).ReadString" },
36
36
// pkg/database/sql
37
- {err : "sql.ErrNoRows" , fun : "(*database/sql.Row).Scan" },
37
+ {err : "database/ sql.ErrNoRows" , fun : "(*database/sql.Row).Scan" },
38
38
// pkg/debug/elf
39
- {err : "io.EOF" , fun : "elf.Open" },
40
- {err : "io.EOF" , fun : "elf.NewFile" },
39
+ {err : "io.EOF" , fun : "debug/ elf.Open" },
40
+ {err : "io.EOF" , fun : "debug/ elf.NewFile" },
41
41
// pkg/io
42
42
{err : "io.EOF" , fun : "(io.Reader).Read" },
43
43
{err : "io.EOF" , fun : "(io.ReaderAt).ReadAt" },
@@ -50,14 +50,14 @@ var allowedErrors = []struct {
50
50
{err : "io.EOF" , fun : "io.ReadFull" },
51
51
{err : "io.ErrUnexpectedEOF" , fun : "io.ReadFull" },
52
52
// pkg/net/http
53
- {err : "http.ErrServerClosed" , fun : "(*net/http.Server).ListenAndServe" },
54
- {err : "http.ErrServerClosed" , fun : "(*net/http.Server).ListenAndServeTLS" },
55
- {err : "http.ErrServerClosed" , fun : "(*net/http.Server).Serve" },
56
- {err : "http.ErrServerClosed" , fun : "(*net/http.Server).ServeTLS" },
57
- {err : "http.ErrServerClosed" , fun : "http.ListenAndServe" },
58
- {err : "http.ErrServerClosed" , fun : "http.ListenAndServeTLS" },
59
- {err : "http.ErrServerClosed" , fun : "http.Serve" },
60
- {err : "http.ErrServerClosed" , fun : "http.ServeTLS" },
53
+ {err : "net/ http.ErrServerClosed" , fun : "(*net/http.Server).ListenAndServe" },
54
+ {err : "net/ http.ErrServerClosed" , fun : "(*net/http.Server).ListenAndServeTLS" },
55
+ {err : "net/ http.ErrServerClosed" , fun : "(*net/http.Server).Serve" },
56
+ {err : "net/ http.ErrServerClosed" , fun : "(*net/http.Server).ServeTLS" },
57
+ {err : "net/ http.ErrServerClosed" , fun : "net/ http.ListenAndServe" },
58
+ {err : "net/ http.ErrServerClosed" , fun : "net/ http.ListenAndServeTLS" },
59
+ {err : "net/ http.ErrServerClosed" , fun : "net/ http.Serve" },
60
+ {err : "net/ http.ErrServerClosed" , fun : "net/ http.ServeTLS" },
61
61
// pkg/os
62
62
{err : "io.EOF" , fun : "(*os.File).Read" },
63
63
{err : "io.EOF" , fun : "(*os.File).ReadAt" },
@@ -80,7 +80,7 @@ func isAllowedErrAndFunc(err, fun string) bool {
80
80
return false
81
81
}
82
82
83
- func isAllowedErrorComparison (info * TypesInfoExt , binExpr * ast.BinaryExpr ) bool {
83
+ func isAllowedErrorComparison (pass * TypesInfoExt , binExpr * ast.BinaryExpr ) bool {
84
84
var errName string // `<package>.<name>`, e.g. `io.EOF`
85
85
var callExprs []* ast.CallExpr
86
86
@@ -91,11 +91,11 @@ func isAllowedErrorComparison(info *TypesInfoExt, binExpr *ast.BinaryExpr) bool
91
91
case * ast.SelectorExpr :
92
92
// A selector which we assume refers to a staticaly declared error
93
93
// in a package.
94
- errName = selectorToString (t )
94
+ errName = selectorToString (pass , t )
95
95
case * ast.Ident :
96
96
// Identifier, most likely to be the `err` variable or whatever
97
97
// produces it.
98
- callExprs = assigningCallExprs (info , t )
98
+ callExprs = assigningCallExprs (pass , t )
99
99
case * ast.CallExpr :
100
100
callExprs = append (callExprs , t )
101
101
}
@@ -115,11 +115,11 @@ func isAllowedErrorComparison(info *TypesInfoExt, binExpr *ast.BinaryExpr) bool
115
115
// allowed.
116
116
return false
117
117
}
118
- if sel , ok := info .Selections [functionSelector ]; ok {
118
+ if sel , ok := pass . TypesInfo .Selections [functionSelector ]; ok {
119
119
functionNames [i ] = fmt .Sprintf ("(%s).%s" , sel .Recv (), sel .Obj ().Name ())
120
120
} else {
121
121
// If there is no selection, assume it is a package.
122
- functionNames [i ] = selectorToString (callExpr .Fun .(* ast.SelectorExpr ))
122
+ functionNames [i ] = selectorToString (pass , callExpr .Fun .(* ast.SelectorExpr ))
123
123
}
124
124
}
125
125
@@ -134,17 +134,17 @@ func isAllowedErrorComparison(info *TypesInfoExt, binExpr *ast.BinaryExpr) bool
134
134
135
135
// assigningCallExprs finds all *ast.CallExpr nodes that are part of an
136
136
// *ast.AssignStmt that assign to the subject identifier.
137
- func assigningCallExprs (info * TypesInfoExt , subject * ast.Ident ) []* ast.CallExpr {
137
+ func assigningCallExprs (pass * TypesInfoExt , subject * ast.Ident ) []* ast.CallExpr {
138
138
if subject .Obj == nil {
139
139
return nil
140
140
}
141
141
142
142
// Find other identifiers that reference this same object. Make sure to
143
143
// exclude the subject identifier as it will cause an infinite recursion
144
144
// and is being used in a read operation anyway.
145
- sobj := info .ObjectOf (subject )
145
+ sobj := pass . TypesInfo .ObjectOf (subject )
146
146
identifiers := []* ast.Ident {}
147
- for _ , ident := range info .IdentifiersForObject [sobj ] {
147
+ for _ , ident := range pass .IdentifiersForObject [sobj ] {
148
148
if subject .Pos () != ident .Pos () {
149
149
identifiers = append (identifiers , ident )
150
150
}
@@ -153,7 +153,7 @@ func assigningCallExprs(info *TypesInfoExt, subject *ast.Ident) []*ast.CallExpr
153
153
// Find out whether the identifiers are part of an assignment statement.
154
154
var callExprs []* ast.CallExpr
155
155
for _ , ident := range identifiers {
156
- parent := info .NodeParent [ident ]
156
+ parent := pass .NodeParent [ident ]
157
157
switch declT := parent .(type ) {
158
158
case * ast.AssignStmt :
159
159
// The identifier is LHS of an assignment.
@@ -181,7 +181,7 @@ func assigningCallExprs(info *TypesInfoExt, subject *ast.Ident) []*ast.CallExpr
181
181
continue
182
182
}
183
183
// The subject was the result of assigning from another identifier.
184
- callExprs = append (callExprs , assigningCallExprs (info , assignT )... )
184
+ callExprs = append (callExprs , assigningCallExprs (pass , assignT )... )
185
185
default :
186
186
// TODO: inconclusive?
187
187
}
@@ -190,9 +190,7 @@ func assigningCallExprs(info *TypesInfoExt, subject *ast.Ident) []*ast.CallExpr
190
190
return callExprs
191
191
}
192
192
193
- func selectorToString (selExpr * ast.SelectorExpr ) string {
194
- if ident , ok := selExpr .X .(* ast.Ident ); ok {
195
- return ident .Name + "." + selExpr .Sel .Name
196
- }
197
- return ""
193
+ func selectorToString (pass * TypesInfoExt , selExpr * ast.SelectorExpr ) string {
194
+ o := pass .TypesInfo .Uses [selExpr .Sel ]
195
+ return fmt .Sprintf ("%s.%s" , o .Pkg ().Path (), o .Name ())
198
196
}
0 commit comments