summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2009-08-28 13:02:34 -0700
committerRob Pike <r@golang.org>2009-08-28 13:02:34 -0700
commit1ea1f47bc4b0c54391f0a8334189139c282c0613 (patch)
treec95d622feb003b32653116dc524ee7a1d1b9345d
parenta2842d35320541cfabc1b3b483ccae85272e1a4c (diff)
downloadgolang-1ea1f47bc4b0c54391f0a8334189139c282c0613.tar.gz
print the value using (in effect) %v when Printf is given mismatched args for its format
Printf("%s", 2) gives %s(int=2) R=rsc DELTA=12 (10 added, 0 deleted, 2 changed) OCL=34042 CL=34044
-rw-r--r--src/pkg/fmt/fmt_test.go4
-rw-r--r--src/pkg/fmt/print.go10
2 files changed, 12 insertions, 2 deletions
diff --git a/src/pkg/fmt/fmt_test.go b/src/pkg/fmt/fmt_test.go
index 76234e552..5e16c5f27 100644
--- a/src/pkg/fmt/fmt_test.go
+++ b/src/pkg/fmt/fmt_test.go
@@ -85,6 +85,10 @@ var fmttests = []fmtTest{
fmtTest{ "%v", &array, "&[1 2 3 4 5]" },
fmtTest{ "%v", &iarray, "&[1 hello 2.5 <nil>]" },
+ // erroneous formats
+ fmtTest{ "", 2, "?(extra int=2)" },
+ fmtTest{ "%d", "hello", "%d(string=hello)%" },
+
// old test/fmt_test.go
fmtTest{ "%d", 1234, "1234" },
fmtTest{ "%d", -1234, "-1234" },
diff --git a/src/pkg/fmt/print.go b/src/pkg/fmt/print.go
index bb1030e72..e5177ef19 100644
--- a/src/pkg/fmt/print.go
+++ b/src/pkg/fmt/print.go
@@ -700,14 +700,20 @@ func (p *pp) doprintf(format string, v *reflect.StructValue) {
default:
badtype:
- s = "%" + string(c) + "(" + field.Type().String() + ")%";
+ s = "%" + string(c) + "(" + field.Type().String() + "=";
+ p.addstr(s);
+ p.printField(field);
+ s= ")%";
}
p.addstr(s);
}
if fieldnum < v.NumField() {
p.addstr("?(extra ");
for ; fieldnum < v.NumField(); fieldnum++ {
- p.addstr(getField(v, fieldnum).Type().String());
+ field := getField(v, fieldnum);
+ p.addstr(field.Type().String());
+ p.addstr("=");
+ p.printField(field);
if fieldnum + 1 < v.NumField() {
p.addstr(", ");
}