Skip to content

Commit 605803f

Browse files
adonovangopherbot
authored andcommitted
go/analysis/passes/loopclosure: simplify using IsMethodNamed
Change-Id: Ic4ff16398189674aa95da59d79eb6004286d04cd Reviewed-on: https://go-review.googlesource.com/c/tools/+/720001 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Madeline Kalil <[email protected]> Auto-Submit: Alan Donovan <[email protected]>
1 parent 2c6e03f commit 605803f

File tree

1 file changed

+7
-29
lines changed

1 file changed

+7
-29
lines changed

go/analysis/passes/loopclosure/loopclosure.go

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,11 @@ func parallelSubtest(info *types.Info, call *ast.CallExpr) []ast.Stmt {
308308
if !ok {
309309
continue
310310
}
311-
expr := exprStmt.X
312-
if isMethodCall(info, expr, "testing", "T", "Parallel") {
313-
call, _ := expr.(*ast.CallExpr)
314-
if call == nil {
315-
continue
316-
}
311+
call, ok := exprStmt.X.(*ast.CallExpr)
312+
if !ok {
313+
continue
314+
}
315+
if isMethodCall(info, call, "testing", "T", "Parallel") {
317316
x, _ := call.Fun.(*ast.SelectorExpr)
318317
if x == nil {
319318
continue
@@ -347,27 +346,6 @@ func unlabel(stmt ast.Stmt) (ast.Stmt, bool) {
347346
}
348347
}
349348

350-
// isMethodCall reports whether expr is a method call of
351-
// <pkgPath>.<typeName>.<method>.
352-
func isMethodCall(info *types.Info, expr ast.Expr, pkgPath, typeName, method string) bool {
353-
call, ok := expr.(*ast.CallExpr)
354-
if !ok {
355-
return false
356-
}
357-
358-
// Check that we are calling a method <method>
359-
// TODO(adonovan): use [typesinternal.IsMethodNamed].
360-
f := typeutil.StaticCallee(info, call)
361-
if f == nil || f.Name() != method {
362-
return false
363-
}
364-
recv := f.Signature().Recv()
365-
if recv == nil {
366-
return false
367-
}
368-
369-
// Check that the receiver is a <pkgPath>.<typeName> or
370-
// *<pkgPath>.<typeName>.
371-
_, named := typesinternal.ReceiverNamed(recv)
372-
return typesinternal.IsTypeNamed(named, pkgPath, typeName)
349+
func isMethodCall(info *types.Info, call *ast.CallExpr, pkgPath, typeName, method string) bool {
350+
return typesinternal.IsMethodNamed(typeutil.Callee(info, call), pkgPath, typeName, method)
373351
}

0 commit comments

Comments
 (0)