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