mirror of
https://github.com/golang/go
synced 2024-11-19 00:44:40 -07:00
go.tools/gc/importer: fix struct tags and parameter names
R=iant CC=golang-codereviews https://golang.org/cl/42280046
This commit is contained in:
parent
87ccd3155a
commit
d4da60d38f
@ -473,7 +473,12 @@ func (p *parser) parseField() (*types.Var, string) {
|
|||||||
}
|
}
|
||||||
tag := ""
|
tag := ""
|
||||||
if p.tok == scanner.String {
|
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
|
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) {
|
func (p *parser) parseParameter() (par *types.Var, isVariadic bool) {
|
||||||
_, name := p.parseName(false)
|
_, name := p.parseName(false)
|
||||||
if name == "" {
|
// remove gc-specific parameter numbering
|
||||||
name = "_" // cannot access unnamed identifiers
|
if i := strings.Index(name, "·"); i >= 0 {
|
||||||
|
name = name[:i]
|
||||||
}
|
}
|
||||||
if p.tok == '.' {
|
if p.tok == '.' {
|
||||||
p.expectSpecial("...")
|
p.expectSpecial("...")
|
||||||
|
@ -128,7 +128,7 @@ var importedObjectTests = []struct {
|
|||||||
{"math.Pi", "const Pi untyped float"},
|
{"math.Pi", "const Pi untyped float"},
|
||||||
{"io.Reader", "type Reader interface{Read(p []byte) (n int, err error)}"},
|
{"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)}"},
|
{"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
|
// TODO(gri) add more tests
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user