MCPcopy Create free account
hub / github.com/despiteallobjections/amigo / interfaceType

Method interfaceType

types/interface.go:116–184  ·  view source on GitHub ↗
(ityp *Interface, iface *InterfaceType, def *Named)

Source from the content-addressed store, hash-verified

114}
115
116func (check *Checker) interfaceType(ityp *Interface, iface *InterfaceType, def *Named) {
117 addEmbedded := func(pos Pos, typ Type) {
118 ityp.embeddeds = append(ityp.embeddeds, typ)
119 if ityp.embedPos == nil {
120 ityp.embedPos = new([]Pos)
121 }
122 *ityp.embedPos = append(*ityp.embedPos, pos)
123 }
124
125 for _, f := range iface.MethodList {
126 if f.Name == nil {
127 addEmbedded(posFor(f.Type), parseUnion(check, f.Type))
128 continue
129 }
130 // f.Name != nil
131
132 // We have a method with name f.Name.
133 name := f.Name.Value
134 if name == "_" {
135 if check.conf.CompilerErrorMessages {
136 check.error(f.Name, "methods must have a unique non-blank name")
137 } else {
138 check.error(f.Name, "invalid method name _")
139 }
140 continue // ignore
141 }
142
143 typ := check.typ(f.Type)
144 sig, _ := typ.(*Signature)
145 if sig == nil {
146 if typ != Typ[Invalid] {
147 check.errorf(f.Type, invalidAST+"%s is not a method signature", typ)
148 }
149 continue // ignore
150 }
151
152 // use named receiver type if available (for better error messages)
153 var recvTyp Type = ityp
154 if def != nil {
155 recvTyp = def
156 }
157 sig.recv = NewVar(f.Name.Pos(), check.pkg, "", recvTyp)
158
159 m := NewFunc(f.Name.Pos(), check.pkg, name, sig)
160 check.recordDef(f.Name, m)
161 ityp.methods = append(ityp.methods, m)
162 }
163
164 // All methods and embedded elements for this interface are collected;
165 // i.e., this interface may be used in a type set computation.
166 ityp.complete = true
167
168 if len(ityp.methods) == 0 && len(ityp.embeddeds) == 0 {
169 // empty interface
170 ityp.tset = &topTypeSet
171 return
172 }
173

Callers 1

typInternalMethod · 0.95

Calls 15

errorMethod · 0.95
typMethod · 0.95
errorfMethod · 0.95
recordDefMethod · 0.95
laterMethod · 0.95
posForFunction · 0.85
parseUnionFunction · 0.85
NewVarFunction · 0.85
NewFuncFunction · 0.85
sortMethodsFunction · 0.85
computeInterfaceTypeSetFunction · 0.85
describefMethod · 0.80

Tested by

no test coverage detected