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

Method setFunction

checker/env.go:269–295  ·  view source on GitHub ↗

setFunction adds the function Decl to the Env. Adds a function decl if one doesn't already exist, then adds all overloads from the Decl. If overload overlaps with an existing overload, adds to the errors in the Env instead.

(fn *decls.FunctionDecl)

Source from the content-addressed store, hash-verified

267// Adds a function decl if one doesn't already exist, then adds all overloads from the Decl.
268// If overload overlaps with an existing overload, adds to the errors in the Env instead.
269func (e *Env) setFunction(fn *decls.FunctionDecl) []errorMsg {
270 errMsgs := make([]errorMsg, 0)
271 current := e.declarations.FindFunction(fn.Name())
272 if current != nil {
273 var err error
274 current, err = current.Merge(fn)
275 if err != nil {
276 return append(errMsgs, errorMsg(err.Error()))
277 }
278 } else {
279 current = fn
280 }
281 for _, overload := range current.OverloadDecls() {
282 for _, macro := range parser.AllMacros {
283 if macro.Function() == current.Name() &&
284 macro.IsReceiverStyle() == overload.IsMemberFunction() &&
285 macro.ArgCount() == len(overload.ArgTypes()) {
286 errMsgs = append(errMsgs, overlappingMacroError(current.Name(), macro.ArgCount()))
287 }
288 }
289 if len(errMsgs) > 0 {
290 return errMsgs
291 }
292 }
293 e.declarations.SetFunction(current)
294 return errMsgs
295}
296
297func maybeMergeConstant(a *decls.VariableDecl, b *decls.VariableDecl) (*decls.VariableDecl, errorMsg) {
298 if b.Value() != nil {

Callers 1

AddFunctionsMethod · 0.95

Calls 13

errorMsgTypeAlias · 0.85
overlappingMacroErrorFunction · 0.85
FindFunctionMethod · 0.80
MergeMethod · 0.80
OverloadDeclsMethod · 0.80
ArgTypesMethod · 0.80
SetFunctionMethod · 0.80
NameMethod · 0.65
FunctionMethod · 0.65
IsReceiverStyleMethod · 0.65
IsMemberFunctionMethod · 0.65
ArgCountMethod · 0.65

Tested by

no test coverage detected