staticcheck: use call graph for checking calls
@@ -2695,16 +2695,9 @@ func (c *Checker) callChecker(rules map[string]CallCheck) func(f *lint.File) {
func (c *Checker) checkCalls(f *lint.File, rules map[string]CallCheck) {
for _, ssafn := range c.funcsForFile(f) {
- for _, b := range ssafn.Blocks {
- for _, ins := range b.Instrs {
- ssacall, ok := ins.(ssa.CallInstruction)
- if !ok {
- continue
- }
- callee := ssacall.Common().StaticCallee()
- if callee == nil {
- continue
- }
+ node := c.CallGraph.CreateNode(ssafn)
+ for _, edge := range node.Out {
+ callee := edge.Callee.Func
obj, ok := callee.Object().(*types.Func)
if !ok {
continue
@@ -2715,27 +2708,27 @@ func (c *Checker) checkCalls(f *lint.File, rules map[string]CallCheck) {
continue
}
var args []*Argument
- ssaargs := ssacall.Common().Args
- if ssacall.Common().Signature().Recv() != nil {
+ ssaargs := edge.Site.Common().Args
+ if callee.Signature.Recv() != nil {
ssaargs = ssaargs[1:]
}
for _, arg := range ssaargs {
if iarg, ok := arg.(*ssa.MakeInterface); ok {
arg = iarg.X
}
- vr := c.funcDescs.Get(ssacall.Parent()).Ranges[arg]
+ vr := c.funcDescs.Get(edge.Site.Parent()).Ranges[arg]
args = append(args, &Argument{Value: Value{arg, vr}})
}
call := &Call{
- Instr: ssacall,
+ Instr: edge.Site,
Args: args,
Checker: c,
- Parent: ssacall.Parent(),
+ Parent: edge.Site.Parent(),
}
r(call)
for idx, arg := range call.Args {
for _, e := range arg.invalids {
- path, _ := astutil.PathEnclosingInterval(f.File, ssacall.Pos(), ssacall.Pos())
+ path, _ := astutil.PathEnclosingInterval(f.File, edge.Site.Pos(), edge.Site.Pos())
if len(path) < 2 {
continue
}
@@ -2752,7 +2745,6 @@ func (c *Checker) checkCalls(f *lint.File, rules map[string]CallCheck) {
}
}
}
-}
func (c *Checker) CheckFlagUsage(f *lint.File) {
for _, ssafn := range c.funcsForFile(f) {
