@@ -16,11 +16,9 @@ import (
16
16
17
17
"golang.org/x/tools/go/analysis"
18
18
"golang.org/x/tools/go/analysis/passes/inspect"
19
- "golang.org/x/tools/go/ast/astutil"
20
19
"golang.org/x/tools/go/ast/inspector"
21
20
"golang.org/x/tools/go/cfg"
22
21
"golang.org/x/tools/go/types/typeutil"
23
- "golang.org/x/tools/internal/typeparams"
24
22
)
25
23
26
24
var Analyzer = & analysis.Analyzer {
@@ -194,7 +192,7 @@ func (c *CFGs) callMayReturn(call *ast.CallExpr) (r bool) {
194
192
// return depending on the parameter type, but in some
195
193
// cases the answer is definite. We let ctrlflow figure
196
194
// that out.
197
- fn := staticCallee (c .pass .TypesInfo , call )
195
+ fn := typeutil . StaticCallee (c .pass .TypesInfo , call )
198
196
if fn == nil {
199
197
return true // callee not statically known; be conservative
200
198
}
@@ -210,50 +208,6 @@ func (c *CFGs) callMayReturn(call *ast.CallExpr) (r bool) {
210
208
return ! c .pass .ImportObjectFact (fn , new (noReturn ))
211
209
}
212
210
213
- // staticCallee returns static function, if any, called by call.
214
- // Effectivelly reduces to typeutil.StaticCallee. In addition,
215
- // returns static function parameterized by a type, if any.
216
- //
217
- // TODO(zpavlinovic): can this be replaced by typeutil.StaticCallee
218
- // in the future?
219
- func staticCallee (info * types.Info , call * ast.CallExpr ) * types.Func {
220
- if fn := typeutil .StaticCallee (info , call ); fn != nil {
221
- return fn
222
- }
223
- return staticTypeParamCallee (info , call )
224
- }
225
-
226
- // staticTypeParamCallee returns the static function in call, if any,
227
- // expected to be parameterized by a type.
228
- func staticTypeParamCallee (info * types.Info , call * ast.CallExpr ) * types.Func {
229
- ix := typeparams .GetIndexExprData (astutil .Unparen (call .Fun ))
230
- if ix == nil {
231
- return nil
232
- }
233
-
234
- var obj types.Object
235
- switch fun := ix .X .(type ) {
236
- case * ast.Ident :
237
- obj = info .Uses [fun ] // type, var, builtin, or declared func
238
- case * ast.SelectorExpr :
239
- if sel , ok := info .Selections [fun ]; ok {
240
- obj = sel .Obj () // method or field
241
- } else {
242
- obj = info .Uses [fun .Sel ] // qualified identifier?
243
- }
244
- }
245
-
246
- if f , ok := obj .(* types.Func ); ok && ! interfaceMethod (f ) {
247
- return f
248
- }
249
- return nil
250
- }
251
-
252
- func interfaceMethod (f * types.Func ) bool {
253
- recv := f .Type ().(* types.Signature ).Recv ()
254
- return recv != nil && types .IsInterface (recv .Type ())
255
- }
256
-
257
211
var panicBuiltin = types .Universe .Lookup ("panic" ).(* types.Builtin )
258
212
259
213
func hasReachableReturn (g * cfg.CFG ) bool {
0 commit comments