-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
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.