fmt.Printf("%U", x) // ERROR "Printf format %U has arg x of wrong type float64"
fmt.Printf("%x", nil) // ERROR "Printf format %x has arg nil of wrong type untyped nil"
fmt.Printf("%X", 2.3) // ERROR "Printf format %X has arg 2.3 of wrong type float64"
- fmt.Printf("%s", stringerv) // ERROR "Printf format %s has arg stringerv of wrong type testdata.stringer"
- fmt.Printf("%t", stringerv) // ERROR "Printf format %t has arg stringerv of wrong type testdata.stringer"
+ fmt.Printf("%s", stringerv) // ERROR "Printf format %s has arg stringerv of wrong type testdata.ptrStringer"
+ fmt.Printf("%t", stringerv) // ERROR "Printf format %t has arg stringerv of wrong type testdata.ptrStringer"
fmt.Printf("%s", embeddedStringerv) // ERROR "Printf format %s has arg embeddedStringerv of wrong type testdata.embeddedStringer"
fmt.Printf("%t", embeddedStringerv) // ERROR "Printf format %t has arg embeddedStringerv of wrong type testdata.embeddedStringer"
fmt.Printf("%q", notstringerv) // ERROR "Printf format %q has arg notstringerv of wrong type testdata.notstringer"
Printf(format, "hi", "there")
Printf(format, "hi") // ERROR "Printf format %s reads arg #2, but call has only 1 arg$"
Printf("%s %d %.3v %q", "str", 4) // ERROR "Printf format %.3v reads arg #3, but call has only 2 args"
- f := new(stringer)
+ f := new(ptrStringer)
f.Warn(0, "%s", "hello", 3) // ERROR "Warn call has possible formatting directive %s"
f.Warnf(0, "%s", "hello", 3) // ERROR "Warnf call needs 1 arg but has 2 args"
f.Warnf(0, "%r", "hello") // ERROR "Warnf format %r has unknown verb r"
panic("don't call - testing only")
}
-type stringer float64
+type stringer int
-var stringerv stringer
+func (stringer) String() string { return "string" }
-func (*stringer) String() string {
+type ptrStringer float64
+
+var stringerv ptrStringer
+
+func (*ptrStringer) String() string {
return "string"
}
-func (*stringer) Warn(int, ...interface{}) string {
+func (*ptrStringer) Warn(int, ...interface{}) string {
return "warn"
}
-func (*stringer) Warnf(int, string, ...interface{}) string {
+func (*ptrStringer) Warnf(int, string, ...interface{}) string {
return "warnf"
}
type embeddedStringer struct {
foo string
- stringer
+ ptrStringer
bar int
}
var recursiveStruct1V = &RecursiveStruct1{}
-// Issue 17798: unexported stringer cannot be formatted.
+// Issue 17798: unexported ptrStringer cannot be formatted.
type unexportedStringer struct {
- t stringer
+ t ptrStringer
}
type unexportedStringerOtherFields struct {
s string
- t stringer
+ t ptrStringer
S string
}
fmt.Println("foo\n") // ERROR "Println arg list ends with redundant newline"
fmt.Println("foo\\n") // not an error
fmt.Println(`foo\n`) // not an error
+
+ intSlice := []int{3, 4}
+ fmt.Printf("%s", intSlice) // ERROR "Printf format %s has arg intSlice of wrong type \[\]int"
+ nonStringerArray := [1]unexportedStringer{{}}
+ fmt.Printf("%s", nonStringerArray) // ERROR "Printf format %s has arg nonStringerArray of wrong type \[1\]testdata.unexportedStringer"
+ fmt.Printf("%s", []stringer{3, 4}) // not an error
+ fmt.Printf("%s", [2]stringer{3, 4}) // not an error
}
// TODO: Disable complaint about '0' for Go 1.10. To be fixed properly in 1.11.