Commit 63661b72 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: refactor checkdupfields API

Allows avoiding the Type.Fields call, which affects prevents
checkdupfields from being called at the more natural point during
dowidth.

Change-Id: I724789c860e7fffba1e8e876e2d74dcfba85d75c
Reviewed-on: https://go-review.googlesource.com/c/go/+/187517Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent cded9f43
......@@ -385,7 +385,7 @@ func dowidth(t *types.Type) {
// We defer calling these functions until after
// setting t.Width and t.Align so the recursive calls
// to dowidth within t.Fields() will succeed.
checkdupfields("method", t)
checkdupfields("method", t.FieldSlice())
offmod(t)
}
......
......@@ -576,10 +576,10 @@ func structfield(n *Node) *types.Field {
// checkdupfields emits errors for duplicately named fields or methods in
// a list of struct or interface types.
func checkdupfields(what string, ts ...*types.Type) {
func checkdupfields(what string, fss ...[]*types.Field) {
seen := make(map[*types.Sym]bool)
for _, t := range ts {
for _, f := range t.Fields().Slice() {
for _, fs := range fss {
for _, f := range fs {
if f.Sym == nil || f.Sym.IsBlank() {
continue
}
......@@ -615,7 +615,7 @@ func tostruct0(t *types.Type, l []*Node) {
}
t.SetFields(fields)
checkdupfields("field", t)
checkdupfields("field", t.FieldSlice())
if !t.Broke() {
checkwidth(t)
......@@ -747,7 +747,7 @@ func functype0(t *types.Type, this *Node, in, out []*Node) {
t.FuncType().Params = tofunargs(in, types.FunargParams)
t.FuncType().Results = tofunargs(out, types.FunargResults)
checkdupfields("argument", t.Recvs(), t.Params(), t.Results())
checkdupfields("argument", t.Recvs().FieldSlice(), t.Params().FieldSlice(), t.Results().FieldSlice())
if t.Recvs().Broke() || t.Results().Broke() || t.Params().Broke() {
t.SetBroke(true)
......
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