Skip to content

x/tools/go/analysis/passes/printf: use induction on interface methods to increase recall #76368

@adonovan

Description

@adonovan

The printf checker checks calls to functions such as fmt.Printf, and functions that have been shown by induction to be (perhaps indirectly) wrappers around such functions. Recently it started checking local functions such as var printf = func(...) { ... }. But it has hitherto been unable to check calls through interface methods such as type Logger interface { Logf(...) } because such methods have no body we can analyze.

I had expected that we would need some kind of annotation mechanism to allow users to assert that Logger.Logf is printf-like, but a chat with @rsc inspired the idea of using assignments to interface types as evidence of intent that a given interface method is printf-like. If we see an assignment of a value of concrete type myLogger to a variable of type Logger (within the package that declares Logger.Logf), and we are able to deduce that myLogger.Logf is printf-like, then we can safely assume Logger.Logf is printf-like too.

We should evaluate this approach as a possible alternative to the need for annotations in many cases.

Metadata

Metadata

Assignees

Labels

AnalysisIssues related to static analysis (vet, x/tools/go/analysis)FeatureRequestIssues asking for a new feature that does not need a proposal.ToolsThis label describes issues relating to any tools in the x/tools repository.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions