]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: avoid redundant call to recordUse for anonymous fields
authorAlan Donovan <adonovan@google.com>
Fri, 4 Nov 2016 21:11:51 +0000 (17:11 -0400)
committerAlan Donovan <adonovan@google.com>
Fri, 4 Nov 2016 21:44:57 +0000 (21:44 +0000)
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 <gri@golang.org>
src/go/types/typexpr.go

index d78d2fa98c2469f863ab064077cee9b21326c43c..6d93a76ebbabe406025436e6ff5f9df9ae7d0560 100644 (file)
@@ -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)