NewInterfaceType returns a new interface for the given methods and embedded types. NewInterfaceType takes ownership of the provided methods and may modify their types by setting missing receivers.
(methods []*Func, embeddeds []Type)
| 31 | // NewInterfaceType takes ownership of the provided methods and may modify their types |
| 32 | // by setting missing receivers. |
| 33 | func NewInterfaceType(methods []*Func, embeddeds []Type) *Interface { |
| 34 | if len(methods) == 0 && len(embeddeds) == 0 { |
| 35 | return &emptyInterface |
| 36 | } |
| 37 | |
| 38 | // set method receivers if necessary |
| 39 | typ := (*Checker)(nil).newInterface() |
| 40 | for _, m := range methods { |
| 41 | if sig := m.typ.(*Signature); sig.recv == nil { |
| 42 | sig.recv = NewVar(m.pos, m.pkg, "", typ) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | // sort for API stability |
| 47 | sortMethods(methods) |
| 48 | |
| 49 | typ.methods = methods |
| 50 | typ.embeddeds = embeddeds |
| 51 | typ.complete = true |
| 52 | |
| 53 | return typ |
| 54 | } |
| 55 | |
| 56 | // check may be nil |
| 57 | func (check *Checker) newInterface() *Interface { |