aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Donovan <adonovan@google.com>2016-11-04 17:11:51 -0400
committerAlan Donovan <adonovan@google.com>2016-11-04 21:44:57 +0000
commit2c6949ec89817caecbb441422fe1d6729ee16462 (patch)
treea291637e3752983186d86b15e407ec46ca1e08c3
parentcfd89164bb6af2d1a660b75ded8c0801372924e2 (diff)
downloadgo-2c6949ec89817caecbb441422fe1d6729ee16462.tar.gz
go-2c6949ec89817caecbb441422fe1d6729ee16462.zip
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 <gri@golang.org>
-rw-r--r--src/go/types/typexpr.go14
1 files 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)