diff --git a/go/types/errors.go b/go/types/errors.go index c95e8936..5eeaa74e 100644 --- a/go/types/errors.go +++ b/go/types/errors.go @@ -258,17 +258,19 @@ func writeType(buf *bytes.Buffer, typ Type) { case *Struct: buf.WriteString("struct{") - for i, f := range t.fields { - if i > 0 { - buf.WriteString("; ") - } - if !f.IsAnonymous { - buf.WriteString(f.Name) - buf.WriteByte(' ') - } - writeType(buf, f.Type) - if tag := t.Tag(i); tag != "" { - fmt.Fprintf(buf, " %q", tag) + if t.fields != nil { + for i, f := range t.fields { + if i > 0 { + buf.WriteString("; ") + } + if !f.IsAnonymous { + buf.WriteString(f.Name) + buf.WriteByte(' ') + } + writeType(buf, f.Type) + if tag := t.Tag(i); tag != "" { + fmt.Fprintf(buf, " %q", tag) + } } } buf.WriteByte('}') @@ -289,13 +291,15 @@ func writeType(buf *bytes.Buffer, typ Type) { case *Interface: buf.WriteString("interface{") - for i, obj := range t.methods.entries { - if i > 0 { - buf.WriteString("; ") + if t.methods != nil { + for i, obj := range t.methods.entries { + 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('}') diff --git a/go/types/expr.go b/go/types/expr.go index 1c1708b9..03d01ae3 100644 --- a/go/types/expr.go +++ b/go/types/expr.go @@ -152,12 +152,14 @@ func (check *checker) collectMethods(scope *Scope, list *ast.FieldList) *Scope { // embedded interface utyp := typ.Underlying() if ityp, ok := utyp.(*Interface); ok { - for _, obj := range ityp.methods.entries { - if alt := methods.Insert(obj); alt != nil { - check.errorf(list.Pos(), "multiple methods named %s", obj.Name()) - obj = nil // for callImplicit, below + if ityp.methods != nil { + for _, obj := range ityp.methods.entries { + if alt := methods.Insert(obj); alt != nil { + 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] { // if utyp is invalid, don't complain (the root cause was reported before)