From 546f269c3bb52b6971c0e2178bb2ab7051a28137 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Thu, 11 Dec 2008 13:24:04 -0800 Subject: [PATCH] if the typestring gives a field name of "?", drop it. R=rsc DELTA=11 (7 added, 0 deleted, 4 changed) OCL=20988 CL=20988 --- src/lib/reflect/all_test.go | 4 ++-- src/lib/reflect/tostring.go | 5 ++++- src/lib/reflect/type.go | 6 +++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lib/reflect/all_test.go b/src/lib/reflect/all_test.go index bb851d49e6..fe16a82f5b 100644 --- a/src/lib/reflect/all_test.go +++ b/src/lib/reflect/all_test.go @@ -118,7 +118,7 @@ export func TestAll(tt *testing.T) { // TODO(r): wrap up better typedump("*chan<-string", "*chan<-string"); typedump("struct {c *chan *int32; d float32}", "struct{c *chan*int32; d float32}"); typedump("*(a int8, b int32)", "*(a int8, b int32)"); - typedump("struct {c *(? *chan *P.integer, ? *int8)}", "struct{c *(? *chan*P.integer, ? *int8)}"); + typedump("struct {c *(? *chan *P.integer, ? *int8)}", "struct{c *(*chan*P.integer, *int8)}"); typedump("struct {a int8; b int32}", "struct{a int8; b int32}"); typedump("struct {a int8; b int8; b int32}", "struct{a int8; b int8; b int32}"); typedump("struct {a int8; b int8; c int8; b int32}", "struct{a int8; b int8; c int8; b int32}"); @@ -149,7 +149,7 @@ export func TestAll(tt *testing.T) { // TODO(r): wrap up better valuedump("*chan<-string", "*chan<-string(0)"); valuedump("struct {c *chan *int32; d float32}", "struct{c *chan*int32; d float32}{*chan*int32(0), 0}"); valuedump("*(a int8, b int32)", "*(a int8, b int32)(0)"); - valuedump("struct {c *(? *chan *P.integer, ? *int8)}", "struct{c *(? *chan*P.integer, ? *int8)}{*(? *chan*P.integer, ? *int8)(0)}"); + valuedump("struct {c *(? *chan *P.integer, ? *int8)}", "struct{c *(*chan*P.integer, *int8)}{*(*chan*P.integer, *int8)(0)}"); valuedump("struct {a int8; b int32}", "struct{a int8; b int32}{0, 0}"); valuedump("struct {a int8; b int8; b int32}", "struct{a int8; b int8; b int32}{0, 0, 0}"); diff --git a/src/lib/reflect/tostring.go b/src/lib/reflect/tostring.go index 8d2d764244..5e658a1304 100644 --- a/src/lib/reflect/tostring.go +++ b/src/lib/reflect/tostring.go @@ -47,7 +47,10 @@ func TypeFieldsToString(t HasFields, sep string) string { var str string; for i := 0; i < t.Len(); i++ { str1, typ, tag, offset := t.Field(i); - str1 += " " + TypeToString(typ, false); + if str1 != "" { + str1 += " " + } + str1 += TypeToString(typ, false); if tag != "" { str1 += " " + DoubleQuote(tag); } diff --git a/src/lib/reflect/type.go b/src/lib/reflect/type.go index ce44ecf937..f1bbe42b82 100644 --- a/src/lib/reflect/type.go +++ b/src/lib/reflect/type.go @@ -690,7 +690,11 @@ func (p *Parser) Fields(sep, term string) *[]Field { } a = a1; } - a[nf].name = p.token; + name := p.token; + if name == "?" { // used to represent a missing name + name = "" + } + a[nf].name = name; p.Next(); a[nf].typ = p.Type(""); if p.token != "" && p.token[0] == '"' { -- 2.48.1