return s != nil && s.Name == "_"
}
-// given receiver of type t (t == r or t == *r)
-// return type to hang methods off (r).
-func methtype(t *Type, mustname int) *Type {
+// methtype returns the underlying type, if any,
+// that owns methods with receiver parameter t.
+// The result is either a named type or an anonymous struct.
+func methtype(t *Type) *Type {
if t == nil {
return nil
}
- // strip away pointer if it's there
+ // Strip away pointer if it's there.
if t.IsPtr() {
if t.Sym != nil {
return nil
}
}
- // need a type name
- if t.Sym == nil && (mustname != 0 || !t.IsStruct()) {
+ // Must be a named type or anonymous struct.
+ if t.Sym == nil && !t.IsStruct() {
return nil
}
- // check types
- if !issimple[t.Etype] {
- switch t.Etype {
- default:
- return nil
-
- case TSTRUCT,
- TARRAY,
- TSLICE,
- TMAP,
- TCHAN,
- TSTRING,
- TFUNC:
- break
- }
+ // Check types.
+ if issimple[t.Etype] {
+ return t
}
-
- return t
+ switch t.Etype {
+ case TARRAY, TCHAN, TFUNC, TMAP, TSLICE, TSTRING, TSTRUCT:
+ return t
+ }
+ return nil
}
func cplxsubtype(et EType) EType {
}
}
- u = methtype(t, 0)
+ u = methtype(t)
if u != nil {
for _, f := range u.Methods().Slice() {
if f.Embedded == 0 && (f.Sym == s || (ignorecase && strings.EqualFold(f.Sym.Name, s.Name))) {
return
}
- u = methtype(t, 0)
+ u = methtype(t)
if u != nil {
for _, f := range u.Methods().Slice() {
if f.Sym.Flags&SymUniq != 0 {
return true
}
- t = methtype(t, 0)
+ t = methtype(t)
if t != nil {
expandmeth(t)
}
// Find the base type: methtype will fail if t
// is not of the form T or *T.
- mt := methtype(t, 0)
+ mt := methtype(t)
if mt == nil {
return false
}
var f2 *Field
if n.Left.Type == t || n.Left.Type.Sym == nil {
- mt := methtype(t, 0)
+ mt := methtype(t)
if mt != nil {
// Use f2->method, not f2->xmethod: adddot has
// already inserted all the necessary embedded dots.