From 2c6949ec89817caecbb441422fe1d6729ee16462 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Fri, 4 Nov 2016 17:11:51 -0400 Subject: [PATCH] go/types: avoid redundant call to recordUse for anonymous fields Anonymous fields are type expressions, and Checker.typexpr already correctly records uses within them. There's no need for a second call, and the second call caused a bug when we implemented aliases. Change-Id: I1bf2429cd4948d68b085e75dfb1bdc03ad8caffd Reviewed-on: https://go-review.googlesource.com/32837 Reviewed-by: Robert Griesemer --- src/go/types/typexpr.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/go/types/typexpr.go b/src/go/types/typexpr.go index d78d2fa98c..6d93a76ebb 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -633,8 +633,7 @@ func (check *Checker) structType(styp *Struct, e *ast.StructType, path []*TypeNa // current field typ and tag var typ Type var tag string - // anonymous != nil indicates an anonymous field. - add := func(field *ast.Field, ident *ast.Ident, anonymous *TypeName, pos token.Pos) { + add := func(field *ast.Field, ident *ast.Ident, anonymous bool, pos token.Pos) { if tag != "" && tags == nil { tags = make([]string, len(fields)) } @@ -643,15 +642,12 @@ func (check *Checker) structType(styp *Struct, e *ast.StructType, path []*TypeNa } name := ident.Name - fld := NewField(pos, check.pkg, name, typ, anonymous != nil) + fld := NewField(pos, check.pkg, name, typ, anonymous) // spec: "Within a struct, non-blank field names must be unique." if name == "_" || check.declareInSet(&fset, pos, fld) { fields = append(fields, fld) check.recordDef(ident, fld) } - if anonymous != nil { - check.recordUse(ident, anonymous) - } } for _, f := range list.List { @@ -660,7 +656,7 @@ func (check *Checker) structType(styp *Struct, e *ast.StructType, path []*TypeNa if len(f.Names) > 0 { // named fields for _, name := range f.Names { - add(f, name, nil, name.Pos()) + add(f, name, false, name.Pos()) } } else { // anonymous field @@ -678,7 +674,7 @@ func (check *Checker) structType(styp *Struct, e *ast.StructType, path []*TypeNa check.errorf(pos, "anonymous field type cannot be unsafe.Pointer") continue } - add(f, name, Universe.Lookup(t.name).(*TypeName), pos) + add(f, name, true, pos) case *Named: // spec: "An embedded type must be specified as a type name @@ -700,7 +696,7 @@ func (check *Checker) structType(styp *Struct, e *ast.StructType, path []*TypeNa continue } } - add(f, name, t.obj, pos) + add(f, name, true, pos) default: check.invalidAST(pos, "anonymous field type %s must be named", typ) -- 2.48.1