mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
go.tools/go/types: don't use nil fields and methods
The change for fields is in anticipation of fields becoming a *Scope. Pointed out by adonovan. R=adonovan CC=golang-dev https://golang.org/cl/9874049
This commit is contained in:
parent
e5f49b1c9f
commit
710a117e33
@ -258,17 +258,19 @@ func writeType(buf *bytes.Buffer, typ Type) {
|
|||||||
|
|
||||||
case *Struct:
|
case *Struct:
|
||||||
buf.WriteString("struct{")
|
buf.WriteString("struct{")
|
||||||
for i, f := range t.fields {
|
if t.fields != nil {
|
||||||
if i > 0 {
|
for i, f := range t.fields {
|
||||||
buf.WriteString("; ")
|
if i > 0 {
|
||||||
}
|
buf.WriteString("; ")
|
||||||
if !f.IsAnonymous {
|
}
|
||||||
buf.WriteString(f.Name)
|
if !f.IsAnonymous {
|
||||||
buf.WriteByte(' ')
|
buf.WriteString(f.Name)
|
||||||
}
|
buf.WriteByte(' ')
|
||||||
writeType(buf, f.Type)
|
}
|
||||||
if tag := t.Tag(i); tag != "" {
|
writeType(buf, f.Type)
|
||||||
fmt.Fprintf(buf, " %q", tag)
|
if tag := t.Tag(i); tag != "" {
|
||||||
|
fmt.Fprintf(buf, " %q", tag)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf.WriteByte('}')
|
buf.WriteByte('}')
|
||||||
@ -289,13 +291,15 @@ func writeType(buf *bytes.Buffer, typ Type) {
|
|||||||
|
|
||||||
case *Interface:
|
case *Interface:
|
||||||
buf.WriteString("interface{")
|
buf.WriteString("interface{")
|
||||||
for i, obj := range t.methods.entries {
|
if t.methods != nil {
|
||||||
if i > 0 {
|
for i, obj := range t.methods.entries {
|
||||||
buf.WriteString("; ")
|
if i > 0 {
|
||||||
|
buf.WriteString("; ")
|
||||||
|
}
|
||||||
|
m := obj.(*Func)
|
||||||
|
buf.WriteString(m.name)
|
||||||
|
writeSignature(buf, m.typ.(*Signature))
|
||||||
}
|
}
|
||||||
m := obj.(*Func)
|
|
||||||
buf.WriteString(m.name)
|
|
||||||
writeSignature(buf, m.typ.(*Signature))
|
|
||||||
}
|
}
|
||||||
buf.WriteByte('}')
|
buf.WriteByte('}')
|
||||||
|
|
||||||
|
@ -152,12 +152,14 @@ func (check *checker) collectMethods(scope *Scope, list *ast.FieldList) *Scope {
|
|||||||
// embedded interface
|
// embedded interface
|
||||||
utyp := typ.Underlying()
|
utyp := typ.Underlying()
|
||||||
if ityp, ok := utyp.(*Interface); ok {
|
if ityp, ok := utyp.(*Interface); ok {
|
||||||
for _, obj := range ityp.methods.entries {
|
if ityp.methods != nil {
|
||||||
if alt := methods.Insert(obj); alt != nil {
|
for _, obj := range ityp.methods.entries {
|
||||||
check.errorf(list.Pos(), "multiple methods named %s", obj.Name())
|
if alt := methods.Insert(obj); alt != nil {
|
||||||
obj = nil // for callImplicit, below
|
check.errorf(list.Pos(), "multiple methods named %s", obj.Name())
|
||||||
|
obj = nil // for callImplicit, below
|
||||||
|
}
|
||||||
|
check.callImplicitObj(f, obj)
|
||||||
}
|
}
|
||||||
check.callImplicitObj(f, obj)
|
|
||||||
}
|
}
|
||||||
} else if utyp != Typ[Invalid] {
|
} else if utyp != Typ[Invalid] {
|
||||||
// if utyp is invalid, don't complain (the root cause was reported before)
|
// if utyp is invalid, don't complain (the root cause was reported before)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user