MCPcopy Create free account
hub / github.com/cel-expr/cel-go / AddOverload

Method AddOverload

common/decls/decls.go:259–291  ·  view source on GitHub ↗

AddOverload ensures that the new overload does not collide with an existing overload signature; however, if the function signatures are identical, the implementation may be rewritten as its difficult to compare functions by object identity.

(overload *OverloadDecl)

Source from the content-addressed store, hash-verified

257// however, if the function signatures are identical, the implementation may be rewritten as its
258// difficult to compare functions by object identity.
259func (f *FunctionDecl) AddOverload(overload *OverloadDecl) error {
260 if f == nil {
261 return fmt.Errorf("nil function cannot add overload: %s", overload.ID())
262 }
263 if overload == nil {
264 return fmt.Errorf("cannot add nil overload to funciton: %s", f.Name())
265 }
266 for oID, o := range f.overloads {
267 if oID != overload.ID() && o.SignatureOverlaps(overload) {
268 return fmt.Errorf("overload signature collision in function %s: %s collides with %s", f.Name(), oID, overload.ID())
269 }
270 if oID == overload.ID() {
271 if o.SignatureEquals(overload) && o.IsNonStrict() == overload.IsNonStrict() {
272 // Allow redefinition of an overload implementation so long as the signatures match.
273 if overload.HasBinding() {
274 f.overloads[oID] = overload
275 }
276 // Allow redefinition of the doc string.
277 if len(overload.doc) != 0 && o.doc != overload.doc {
278 o.doc = overload.doc
279 }
280 return nil
281 }
282 return fmt.Errorf("overload redefinition in function. %s: %s has multiple definitions", f.Name(), oID)
283 }
284 if overload.HasLateBinding() != o.HasLateBinding() {
285 return fmt.Errorf("overload with late binding cannot be added to function %s: cannot mix late and non-late bindings", f.Name())
286 }
287 }
288 f.overloadOrdinals = append(f.overloadOrdinals, overload.ID())
289 f.overloads[overload.ID()] = overload
290 return nil
291}
292
293// OverloadDecls returns the overload declarations in the order in which they were declared.
294func (f *FunctionDecl) OverloadDecls() []*OverloadDecl {

Callers 3

TestNilFunctionFunction · 0.95
MergeMethod · 0.95
newOverloadFunction · 0.45

Calls 7

NameMethod · 0.95
SignatureOverlapsMethod · 0.80
SignatureEqualsMethod · 0.80
IsNonStrictMethod · 0.80
HasBindingMethod · 0.80
IDMethod · 0.65
HasLateBindingMethod · 0.45

Tested by 1

TestNilFunctionFunction · 0.76