Commit 2c6949ec authored by Alan Donovan's avatar Alan Donovan

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/32837Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent cfd89164
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment