github.com/stingnevermore/go@v0.0.0-20180120041312-3810f5bfed72/src/cmd/vet/testdata/print.go (about) 1 // Copyright 2010 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // This file contains tests for the printf checker. 6 7 // TODO(rsc): The user-defined wrapper tests are commented out 8 // because they produced too many false positives when vet was 9 // enabled during go test. See the TODO in ../print.go for a plan 10 // to fix that; when it's fixed, uncomment the user-defined wrapper tests. 11 12 package testdata 13 14 import ( 15 "fmt" 16 . "fmt" 17 "math" 18 "os" 19 "testing" 20 "unsafe" // just for test case printing unsafe.Pointer 21 // For testing printf-like functions from external package. 22 // "github.com/foobar/externalprintf" 23 ) 24 25 func UnsafePointerPrintfTest() { 26 var up unsafe.Pointer 27 fmt.Printf("%p, %x %X", up, up, up) 28 } 29 30 // Error methods that do not satisfy the Error interface and should be checked. 31 type errorTest1 int 32 33 func (errorTest1) Error(...interface{}) string { 34 return "hi" 35 } 36 37 type errorTest2 int // Analogous to testing's *T type. 38 func (errorTest2) Error(...interface{}) { 39 } 40 41 type errorTest3 int 42 43 func (errorTest3) Error() { // No return value. 44 } 45 46 type errorTest4 int 47 48 func (errorTest4) Error() int { // Different return type. 49 return 3 50 } 51 52 type errorTest5 int 53 54 func (errorTest5) error() { // niladic; don't complain if no args (was bug) 55 } 56 57 // This function never executes, but it serves as a simple test for the program. 58 // Test with make test. 59 func PrintfTests() { 60 var b bool 61 var i int 62 var r rune 63 var s string 64 var x float64 65 var p *int 66 var imap map[int]int 67 var fslice []float64 68 var c complex64 69 // Some good format/argtypes 70 fmt.Printf("") 71 fmt.Printf("%b %b %b", 3, i, x) 72 fmt.Printf("%c %c %c %c", 3, i, 'x', r) 73 fmt.Printf("%d %d %d", 3, i, imap) 74 fmt.Printf("%e %e %e %e", 3e9, x, fslice, c) 75 fmt.Printf("%E %E %E %E", 3e9, x, fslice, c) 76 fmt.Printf("%f %f %f %f", 3e9, x, fslice, c) 77 fmt.Printf("%F %F %F %F", 3e9, x, fslice, c) 78 fmt.Printf("%g %g %g %g", 3e9, x, fslice, c) 79 fmt.Printf("%G %G %G %G", 3e9, x, fslice, c) 80 fmt.Printf("%b %b %b %b", 3e9, x, fslice, c) 81 fmt.Printf("%o %o", 3, i) 82 fmt.Printf("%p %p", p, nil) 83 fmt.Printf("%q %q %q %q", 3, i, 'x', r) 84 fmt.Printf("%s %s %s", "hi", s, []byte{65}) 85 fmt.Printf("%t %t", true, b) 86 fmt.Printf("%T %T", 3, i) 87 fmt.Printf("%U %U", 3, i) 88 fmt.Printf("%v %v", 3, i) 89 fmt.Printf("%x %x %x %x", 3, i, "hi", s) 90 fmt.Printf("%X %X %X %X", 3, i, "hi", s) 91 fmt.Printf("%.*s %d %g", 3, "hi", 23, 2.3) 92 fmt.Printf("%s", &stringerv) 93 fmt.Printf("%v", &stringerv) 94 fmt.Printf("%T", &stringerv) 95 fmt.Printf("%s", &embeddedStringerv) 96 fmt.Printf("%v", &embeddedStringerv) 97 fmt.Printf("%T", &embeddedStringerv) 98 fmt.Printf("%v", notstringerv) 99 fmt.Printf("%T", notstringerv) 100 fmt.Printf("%q", stringerarrayv) 101 fmt.Printf("%v", stringerarrayv) 102 fmt.Printf("%s", stringerarrayv) 103 fmt.Printf("%v", notstringerarrayv) 104 fmt.Printf("%T", notstringerarrayv) 105 fmt.Printf("%d", new(Formatter)) 106 fmt.Printf("%*%", 2) // Ridiculous but allowed. 107 fmt.Printf("%s", interface{}(nil)) // Nothing useful we can say. 108 109 fmt.Printf("%g", 1+2i) 110 fmt.Printf("%#e %#E %#f %#F %#g %#G", 1.2, 1.2, 1.2, 1.2, 1.2, 1.2) // OK since Go 1.9 111 // Some bad format/argTypes 112 fmt.Printf("%b", "hi") // ERROR "Printf format %b has arg \x22hi\x22 of wrong type string" 113 fmt.Printf("%t", c) // ERROR "Printf format %t has arg c of wrong type complex64" 114 fmt.Printf("%t", 1+2i) // ERROR "Printf format %t has arg 1 \+ 2i of wrong type complex128" 115 fmt.Printf("%c", 2.3) // ERROR "Printf format %c has arg 2.3 of wrong type float64" 116 fmt.Printf("%d", 2.3) // ERROR "Printf format %d has arg 2.3 of wrong type float64" 117 fmt.Printf("%e", "hi") // ERROR "Printf format %e has arg \x22hi\x22 of wrong type string" 118 fmt.Printf("%E", true) // ERROR "Printf format %E has arg true of wrong type bool" 119 fmt.Printf("%f", "hi") // ERROR "Printf format %f has arg \x22hi\x22 of wrong type string" 120 fmt.Printf("%F", 'x') // ERROR "Printf format %F has arg 'x' of wrong type rune" 121 fmt.Printf("%g", "hi") // ERROR "Printf format %g has arg \x22hi\x22 of wrong type string" 122 fmt.Printf("%g", imap) // ERROR "Printf format %g has arg imap of wrong type map\[int\]int" 123 fmt.Printf("%G", i) // ERROR "Printf format %G has arg i of wrong type int" 124 fmt.Printf("%o", x) // ERROR "Printf format %o has arg x of wrong type float64" 125 fmt.Printf("%p", 23) // ERROR "Printf format %p has arg 23 of wrong type int" 126 fmt.Printf("%q", x) // ERROR "Printf format %q has arg x of wrong type float64" 127 fmt.Printf("%s", b) // ERROR "Printf format %s has arg b of wrong type bool" 128 fmt.Printf("%s", byte(65)) // ERROR "Printf format %s has arg byte\(65\) of wrong type byte" 129 fmt.Printf("%t", 23) // ERROR "Printf format %t has arg 23 of wrong type int" 130 fmt.Printf("%U", x) // ERROR "Printf format %U has arg x of wrong type float64" 131 fmt.Printf("%x", nil) // ERROR "Printf format %x has arg nil of wrong type untyped nil" 132 fmt.Printf("%X", 2.3) // ERROR "Printf format %X has arg 2.3 of wrong type float64" 133 fmt.Printf("%s", stringerv) // ERROR "Printf format %s has arg stringerv of wrong type testdata.stringer" 134 fmt.Printf("%t", stringerv) // ERROR "Printf format %t has arg stringerv of wrong type testdata.stringer" 135 fmt.Printf("%s", embeddedStringerv) // ERROR "Printf format %s has arg embeddedStringerv of wrong type testdata.embeddedStringer" 136 fmt.Printf("%t", embeddedStringerv) // ERROR "Printf format %t has arg embeddedStringerv of wrong type testdata.embeddedStringer" 137 fmt.Printf("%q", notstringerv) // ERROR "Printf format %q has arg notstringerv of wrong type testdata.notstringer" 138 fmt.Printf("%t", notstringerv) // ERROR "Printf format %t has arg notstringerv of wrong type testdata.notstringer" 139 fmt.Printf("%t", stringerarrayv) // ERROR "Printf format %t has arg stringerarrayv of wrong type testdata.stringerarray" 140 fmt.Printf("%t", notstringerarrayv) // ERROR "Printf format %t has arg notstringerarrayv of wrong type testdata.notstringerarray" 141 fmt.Printf("%q", notstringerarrayv) // ERROR "Printf format %q has arg notstringerarrayv of wrong type testdata.notstringerarray" 142 fmt.Printf("%d", BoolFormatter(true)) // ERROR "Printf format %d has arg BoolFormatter\(true\) of wrong type testdata.BoolFormatter" 143 fmt.Printf("%z", FormatterVal(true)) // correct (the type is responsible for formatting) 144 fmt.Printf("%d", FormatterVal(true)) // correct (the type is responsible for formatting) 145 fmt.Printf("%s", nonemptyinterface) // correct (the type is responsible for formatting) 146 fmt.Printf("%.*s %d %6g", 3, "hi", 23, 'x') // ERROR "Printf format %6g has arg 'x' of wrong type rune" 147 fmt.Println() // not an error 148 fmt.Println("%s", "hi") // ERROR "Println call has possible formatting directive %s" 149 fmt.Println("%v", "hi") // ERROR "Println call has possible formatting directive %v" 150 fmt.Println("0.0%") // correct (trailing % couldn't be a formatting directive) 151 fmt.Printf("%s", "hi", 3) // ERROR "Printf call needs 1 arg but has 2 args" 152 _ = fmt.Sprintf("%"+("s"), "hi", 3) // ERROR "Sprintf call needs 1 arg but has 2 args" 153 fmt.Printf("%s%%%d", "hi", 3) // correct 154 fmt.Printf("%08s", "woo") // correct 155 fmt.Printf("% 8s", "woo") // correct 156 fmt.Printf("%.*d", 3, 3) // correct 157 fmt.Printf("%.*d x", 3, 3, 3, 3) // ERROR "Printf call needs 2 args but has 4 args" 158 fmt.Printf("%.*d x", "hi", 3) // ERROR "Printf format %.*d uses non-int \x22hi\x22 as argument of \*" 159 fmt.Printf("%.*d x", i, 3) // correct 160 fmt.Printf("%.*d x", s, 3) // ERROR "Printf format %.\*d uses non-int s as argument of \*" 161 fmt.Printf("%*% x", 0.22) // ERROR "Printf format %\*% uses non-int 0.22 as argument of \*" 162 fmt.Printf("%q %q", multi()...) // ok 163 fmt.Printf("%#q", `blah`) // ok 164 // printf("now is the time", "buddy") // no error "printf call has arguments but no formatting directives" 165 Printf("now is the time", "buddy") // ERROR "Printf call has arguments but no formatting directives" 166 Printf("hi") // ok 167 const format = "%s %s\n" 168 Printf(format, "hi", "there") 169 Printf(format, "hi") // ERROR "Printf format %s reads arg #2, but call has only 1 arg$" 170 Printf("%s %d %.3v %q", "str", 4) // ERROR "Printf format %.3v reads arg #3, but call has only 2 args" 171 f := new(stringer) 172 f.Warn(0, "%s", "hello", 3) // ERROR "Warn call has possible formatting directive %s" 173 f.Warnf(0, "%s", "hello", 3) // ERROR "Warnf call needs 1 arg but has 2 args" 174 f.Warnf(0, "%r", "hello") // ERROR "Warnf format %r has unknown verb r" 175 f.Warnf(0, "%#s", "hello") // ERROR "Warnf format %#s has unrecognized flag #" 176 fmt.Printf("%#s", FormatterVal(true)) // correct (the type is responsible for formatting) 177 Printf("d%", 2) // ERROR "Printf format % is missing verb at end of string" 178 Printf("%d", percentDV) 179 Printf("%d", &percentDV) 180 Printf("%d", notPercentDV) // ERROR "Printf format %d has arg notPercentDV of wrong type testdata.notPercentDStruct" 181 Printf("%d", ¬PercentDV) // ERROR "Printf format %d has arg ¬PercentDV of wrong type \*testdata.notPercentDStruct" 182 Printf("%p", ¬PercentDV) // Works regardless: we print it as a pointer. 183 Printf("%s", percentSV) 184 Printf("%s", &percentSV) 185 // Good argument reorderings. 186 Printf("%[1]d", 3) 187 Printf("%[1]*d", 3, 1) 188 Printf("%[2]*[1]d", 1, 3) 189 Printf("%[2]*.[1]*[3]d", 2, 3, 4) 190 fmt.Fprintf(os.Stderr, "%[2]*.[1]*[3]d", 2, 3, 4) // Use Fprintf to make sure we count arguments correctly. 191 // Bad argument reorderings. 192 Printf("%[xd", 3) // ERROR "Printf format %\[xd is missing closing \]" 193 Printf("%[x]d x", 3) // ERROR "Printf format has invalid argument index \[x\]" 194 Printf("%[3]*s x", "hi", 2) // ERROR "Printf format has invalid argument index \[3\]" 195 _ = fmt.Sprintf("%[3]d x", 2) // ERROR "Sprintf format has invalid argument index \[3\]" 196 Printf("%[2]*.[1]*[3]d x", 2, "hi", 4) // ERROR "Printf format %\[2]\*\.\[1\]\*\[3\]d uses non-int \x22hi\x22 as argument of \*" 197 Printf("%[0]s x", "arg1") // ERROR "Printf format has invalid argument index \[0\]" 198 Printf("%[0]d x", 1) // ERROR "Printf format has invalid argument index \[0\]" 199 // Something that satisfies the error interface. 200 var e error 201 fmt.Println(e.Error()) // ok 202 // Something that looks like an error interface but isn't, such as the (*T).Error method 203 // in the testing package. 204 var et1 *testing.T 205 et1.Error() // ok 206 et1.Error("hi") // ok 207 et1.Error("%d", 3) // ERROR "Error call has possible formatting directive %d" 208 var et3 errorTest3 209 et3.Error() // ok, not an error method. 210 var et4 errorTest4 211 et4.Error() // ok, not an error method. 212 var et5 errorTest5 213 et5.error() // ok, not an error method. 214 // Interfaces can be used with any verb. 215 var iface interface { 216 ToTheMadness() bool // Method ToTheMadness usually returns false 217 } 218 fmt.Printf("%f", iface) // ok: fmt treats interfaces as transparent and iface may well have a float concrete type 219 // Can't print a function. 220 Printf("%d", someFunction) // ERROR "Printf format %d arg someFunction is a func value, not called" 221 Printf("%v", someFunction) // ERROR "Printf format %v arg someFunction is a func value, not called" 222 Println(someFunction) // ERROR "Println arg someFunction is a func value, not called" 223 Printf("%p", someFunction) // ok: maybe someone wants to see the pointer 224 Printf("%T", someFunction) // ok: maybe someone wants to see the type 225 // Bug: used to recur forever. 226 Printf("%p %x", recursiveStructV, recursiveStructV.next) 227 Printf("%p %x", recursiveStruct1V, recursiveStruct1V.next) 228 Printf("%p %x", recursiveSliceV, recursiveSliceV) 229 Printf("%p %x", recursiveMapV, recursiveMapV) 230 // Special handling for Log. 231 math.Log(3) // OK 232 var t *testing.T 233 t.Log("%d", 3) // ERROR "Log call has possible formatting directive %d" 234 t.Logf("%d", 3) 235 t.Logf("%d", "hi") // ERROR "Logf format %d has arg \x22hi\x22 of wrong type string" 236 237 // Errorf(1, "%d", 3) // OK 238 // Errorf(1, "%d", "hi") // no error "Errorf format %d has arg \x22hi\x22 of wrong type string" 239 240 // Multiple string arguments before variadic args 241 // errorf("WARNING", "foobar") // OK 242 // errorf("INFO", "s=%s, n=%d", "foo", 1) // OK 243 // errorf("ERROR", "%d") // no error "errorf format %d reads arg #1, but call has only 0 args" 244 245 // Printf from external package 246 // externalprintf.Printf("%d", 42) // OK 247 // externalprintf.Printf("foobar") // OK 248 // level := 123 249 // externalprintf.Logf(level, "%d", 42) // OK 250 // externalprintf.Errorf(level, level, "foo %q bar", "foobar") // OK 251 // externalprintf.Logf(level, "%d") // no error "Logf format %d reads arg #1, but call has only 0 args" 252 // var formatStr = "%s %s" 253 // externalprintf.Sprintf(formatStr, "a", "b") // OK 254 // externalprintf.Logf(level, formatStr, "a", "b") // OK 255 256 // user-defined Println-like functions 257 ss := &someStruct{} 258 ss.Log(someFunction, "foo") // OK 259 ss.Error(someFunction, someFunction) // OK 260 ss.Println() // OK 261 ss.Println(1.234, "foo") // OK 262 ss.Println(1, someFunction) // no error "Println arg someFunction is a func value, not called" 263 ss.log(someFunction) // OK 264 ss.log(someFunction, "bar", 1.33) // OK 265 ss.log(someFunction, someFunction) // no error "log arg someFunction is a func value, not called" 266 267 // indexed arguments 268 Printf("%d %[3]d %d %[2]d x", 1, 2, 3, 4) // OK 269 Printf("%d %[0]d %d %[2]d x", 1, 2, 3, 4) // ERROR "Printf format has invalid argument index \[0\]" 270 Printf("%d %[3]d %d %[-2]d x", 1, 2, 3, 4) // ERROR "Printf format has invalid argument index \[-2\]" 271 Printf("%d %[3]d %d %[2234234234234]d x", 1, 2, 3, 4) // ERROR "Printf format has invalid argument index \[2234234234234\]" 272 Printf("%d %[3]d %-10d %[2]d x", 1, 2, 3) // ERROR "Printf format %-10d reads arg #4, but call has only 3 args" 273 Printf("%d %[3]d %d %[2]d x", 1, 2, 3, 4, 5) // ERROR "Printf call needs 4 args but has 5 args" 274 Printf("%[1][3]d x", 1, 2) // ERROR "Printf format %\[1\]\[ has unknown verb \[" 275 276 // wrote Println but meant Fprintln 277 Printf("%p\n", os.Stdout) // OK 278 Println(os.Stdout, "hello") // ERROR "Println does not take io.Writer but has first arg os.Stdout" 279 280 Printf(someString(), "hello") // OK 281 282 } 283 284 func someString() string { return "X" } 285 286 type someStruct struct{} 287 288 // Log is non-variadic user-define Println-like function. 289 // Calls to this func must be skipped when checking 290 // for Println-like arguments. 291 func (ss *someStruct) Log(f func(), s string) {} 292 293 // Error is variadic user-define Println-like function. 294 // Calls to this func mustn't be checked for Println-like arguments, 295 // since variadic arguments type isn't interface{}. 296 func (ss *someStruct) Error(args ...func()) {} 297 298 // Println is variadic user-defined Println-like function. 299 // Calls to this func must be checked for Println-like arguments. 300 func (ss *someStruct) Println(args ...interface{}) {} 301 302 // log is variadic user-defined Println-like function. 303 // Calls to this func must be checked for Println-like arguments. 304 func (ss *someStruct) log(f func(), args ...interface{}) {} 305 306 // A function we use as a function value; it has no other purpose. 307 func someFunction() {} 308 309 /* 310 // Printf is used by the test so we must declare it. 311 func Printf(format string, args ...interface{}) { 312 panic("don't call - testing only") 313 } 314 315 // Println is used by the test so we must declare it. 316 func Println(args ...interface{}) { 317 panic("don't call - testing only") 318 } 319 320 // Logf is used by the test so we must declare it. 321 func Logf(format string, args ...interface{}) { 322 panic("don't call - testing only") 323 } 324 325 // Log is used by the test so we must declare it. 326 func Log(args ...interface{}) { 327 panic("don't call - testing only") 328 } 329 */ 330 331 // printf is used by the test so we must declare it. 332 func printf(format string, args ...interface{}) { 333 panic("don't call - testing only") 334 } 335 336 /* 337 // Errorf is used by the test for a case in which the first parameter 338 // is not a format string. 339 func Errorf(i int, format string, args ...interface{}) { 340 panic("don't call - testing only") 341 } 342 343 // errorf is used by the test for a case in which the function accepts multiple 344 // string parameters before variadic arguments 345 func errorf(level, format string, args ...interface{}) { 346 panic("don't call - testing only") 347 } 348 */ 349 350 // multi is used by the test. 351 func multi() []interface{} { 352 panic("don't call - testing only") 353 } 354 355 type stringer float64 356 357 var stringerv stringer 358 359 func (*stringer) String() string { 360 return "string" 361 } 362 363 func (*stringer) Warn(int, ...interface{}) string { 364 return "warn" 365 } 366 367 func (*stringer) Warnf(int, string, ...interface{}) string { 368 return "warnf" 369 } 370 371 type embeddedStringer struct { 372 foo string 373 stringer 374 bar int 375 } 376 377 var embeddedStringerv embeddedStringer 378 379 type notstringer struct { 380 f float64 381 } 382 383 var notstringerv notstringer 384 385 type stringerarray [4]float64 386 387 func (stringerarray) String() string { 388 return "string" 389 } 390 391 var stringerarrayv stringerarray 392 393 type notstringerarray [4]float64 394 395 var notstringerarrayv notstringerarray 396 397 var nonemptyinterface = interface { 398 f() 399 }(nil) 400 401 // A data type we can print with "%d". 402 type percentDStruct struct { 403 a int 404 b []byte 405 c *float64 406 } 407 408 var percentDV percentDStruct 409 410 // A data type we cannot print correctly with "%d". 411 type notPercentDStruct struct { 412 a int 413 b []byte 414 c bool 415 } 416 417 var notPercentDV notPercentDStruct 418 419 // A data type we can print with "%s". 420 type percentSStruct struct { 421 a string 422 b []byte 423 C stringerarray 424 } 425 426 var percentSV percentSStruct 427 428 type recursiveStringer int 429 430 func (s recursiveStringer) String() string { 431 _ = fmt.Sprintf("%d", s) 432 _ = fmt.Sprintf("%#v", s) 433 _ = fmt.Sprintf("%v", s) // ERROR "Sprintf format %v with arg s causes recursive String method call" 434 _ = fmt.Sprintf("%v", &s) // ERROR "Sprintf format %v with arg &s causes recursive String method call" 435 _ = fmt.Sprintf("%T", s) // ok; does not recursively call String 436 return fmt.Sprintln(s) // ERROR "Sprintln arg s causes recursive call to String method" 437 } 438 439 type recursivePtrStringer int 440 441 func (p *recursivePtrStringer) String() string { 442 _ = fmt.Sprintf("%v", *p) 443 return fmt.Sprintln(p) // ERROR "Sprintln arg p causes recursive call to String method" 444 } 445 446 type BoolFormatter bool 447 448 func (*BoolFormatter) Format(fmt.State, rune) { 449 } 450 451 // Formatter with value receiver 452 type FormatterVal bool 453 454 func (FormatterVal) Format(fmt.State, rune) { 455 } 456 457 type RecursiveSlice []RecursiveSlice 458 459 var recursiveSliceV = &RecursiveSlice{} 460 461 type RecursiveMap map[int]RecursiveMap 462 463 var recursiveMapV = make(RecursiveMap) 464 465 type RecursiveStruct struct { 466 next *RecursiveStruct 467 } 468 469 var recursiveStructV = &RecursiveStruct{} 470 471 type RecursiveStruct1 struct { 472 next *RecursiveStruct2 473 } 474 475 type RecursiveStruct2 struct { 476 next *RecursiveStruct1 477 } 478 479 var recursiveStruct1V = &RecursiveStruct1{} 480 481 // Issue 17798: unexported stringer cannot be formatted. 482 type unexportedStringer struct { 483 t stringer 484 } 485 type unexportedStringerOtherFields struct { 486 s string 487 t stringer 488 S string 489 } 490 491 // Issue 17798: unexported error cannot be formatted. 492 type unexportedError struct { 493 e error 494 } 495 type unexportedErrorOtherFields struct { 496 s string 497 e error 498 S string 499 } 500 501 type errorer struct{} 502 503 func (e errorer) Error() string { return "errorer" } 504 505 func UnexportedStringerOrError() { 506 us := unexportedStringer{} 507 fmt.Printf("%s", us) // ERROR "Printf format %s has arg us of wrong type testdata.unexportedStringer" 508 fmt.Printf("%s", &us) // ERROR "Printf format %s has arg &us of wrong type [*]testdata.unexportedStringer" 509 510 usf := unexportedStringerOtherFields{ 511 s: "foo", 512 S: "bar", 513 } 514 fmt.Printf("%s", usf) // ERROR "Printf format %s has arg usf of wrong type testdata.unexportedStringerOtherFields" 515 fmt.Printf("%s", &usf) // ERROR "Printf format %s has arg &usf of wrong type [*]testdata.unexportedStringerOtherFields" 516 517 ue := unexportedError{ 518 e: &errorer{}, 519 } 520 fmt.Printf("%s", ue) // ERROR "Printf format %s has arg ue of wrong type testdata.unexportedError" 521 fmt.Printf("%s", &ue) // ERROR "Printf format %s has arg &ue of wrong type [*]testdata.unexportedError" 522 523 uef := unexportedErrorOtherFields{ 524 s: "foo", 525 e: &errorer{}, 526 S: "bar", 527 } 528 fmt.Printf("%s", uef) // ERROR "Printf format %s has arg uef of wrong type testdata.unexportedErrorOtherFields" 529 fmt.Printf("%s", &uef) // ERROR "Printf format %s has arg &uef of wrong type [*]testdata.unexportedErrorOtherFields" 530 531 fmt.Println("foo\n", "bar") // not an error 532 fmt.Println("foo\n") // ERROR "Println arg list ends with redundant newline" 533 fmt.Println("foo\\n") // not an error 534 fmt.Println(`foo\n`) // not an error 535 }