From d4da60d38fd7bdc2350677085b6973aae7385d70 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 20 Dec 2013 15:17:16 -0800 Subject: [PATCH] go.tools/gc/importer: fix struct tags and parameter names R=iant CC=golang-codereviews https://golang.org/cl/42280046 --- go/gcimporter/gcimporter.go | 12 +++++++++--- go/gcimporter/gcimporter_test.go | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/go/gcimporter/gcimporter.go b/go/gcimporter/gcimporter.go index 18e6f7b459..0812de7ed9 100644 --- a/go/gcimporter/gcimporter.go +++ b/go/gcimporter/gcimporter.go @@ -473,7 +473,12 @@ func (p *parser) parseField() (*types.Var, string) { } tag := "" if p.tok == scanner.String { - tag = p.expect(scanner.String) + s := p.expect(scanner.String) + var err error + tag, err = strconv.Unquote(s) + if err != nil { + p.errorf("invalid struct tag %s: %s", s, err) + } } return types.NewField(token.NoPos, pkg, name, typ, anonymous), tag } @@ -509,8 +514,9 @@ func (p *parser) parseStructType() types.Type { // func (p *parser) parseParameter() (par *types.Var, isVariadic bool) { _, name := p.parseName(false) - if name == "" { - name = "_" // cannot access unnamed identifiers + // remove gc-specific parameter numbering + if i := strings.Index(name, "·"); i >= 0 { + name = name[:i] } if p.tok == '.' { p.expectSpecial("...") diff --git a/go/gcimporter/gcimporter_test.go b/go/gcimporter/gcimporter_test.go index 4e64e79ac2..094c5f5853 100644 --- a/go/gcimporter/gcimporter_test.go +++ b/go/gcimporter/gcimporter_test.go @@ -128,7 +128,7 @@ var importedObjectTests = []struct { {"math.Pi", "const Pi untyped float"}, {"io.Reader", "type Reader interface{Read(p []byte) (n int, err error)}"}, {"io.ReadWriter", "type ReadWriter interface{Read(p []byte) (n int, err error); Write(p []byte) (n int, err error)}"}, - {"math.Sin", "func Sin(x·2 float64) (_ float64)"}, + {"math.Sin", "func Sin(x float64) float64"}, // TODO(gri) add more tests }