func (f *File) checkPrint(call *ast.CallExpr, name string) {
firstArg := 0
typ := f.pkg.types[call.Fun].Type
- if typ != nil {
- if sig, ok := typ.(*types.Signature); ok {
- if !sig.Variadic() {
- // Skip checking non-variadic functions.
- return
- }
- params := sig.Params()
- firstArg = params.Len() - 1
-
- typ := params.At(firstArg).Type()
- typ = typ.(*types.Slice).Elem()
- it, ok := typ.(*types.Interface)
- if !ok || !it.Empty() {
- // Skip variadic functions accepting non-interface{} args.
- return
- }
+ if typ == nil {
+ // Skip checking functions with unknown type.
+ return
+ }
+ if sig, ok := typ.(*types.Signature); ok {
+ if !sig.Variadic() {
+ // Skip checking non-variadic functions.
+ return
+ }
+ params := sig.Params()
+ firstArg = params.Len() - 1
+
+ typ := params.At(firstArg).Type()
+ typ = typ.(*types.Slice).Elem()
+ it, ok := typ.(*types.Interface)
+ if !ok || !it.Empty() {
+ // Skip variadic functions accepting non-interface{} args.
+ return
}
}
args := call.Args
import (
"fmt"
+ "io"
"math"
"os"
"unsafe" // just for test case printing unsafe.Pointer
panic("don't call - testing only")
}
+// Println is used by the test so we must declare it.
+func Println(args ...interface{}) {
+ panic("don't call - testing only")
+}
+
// Logf is used by the test so we must declare it.
func Logf(format string, args ...interface{}) {
panic("don't call - testing only")
}
+// Log is used by the test so we must declare it.
+func Log(args ...interface{}) {
+ panic("don't call - testing only")
+}
+
// printf is used by the test so we must declare it.
func printf(format string, args ...interface{}) {
panic("don't call - testing only")
func (int) String() {
return ""
}
+
+func (s *unknownStruct) Fprintln(w io.Writer, s string) {}
+
+func UnknownStructFprintln() {
+ s := unknownStruct{}
+ s.Fprintln(os.Stdout, "hello, world!") // OK
+}