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

Method setFunction

checker/env.go:250–276  ·  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

248// Adds a function decl if one doesn't already exist, then adds all overloads from the Decl.
249// If overload overlaps with an existing overload, adds to the errors in the Env instead.
250func (e *Env) setFunction(fn *decls.FunctionDecl) []errorMsg {
251 errMsgs := make([]errorMsg, 0)
252 current := e.declarations.FindFunction(fn.Name())
253 if current != nil {
254 var err error
255 current, err = current.Merge(fn)
256 if err != nil {
257 return append(errMsgs, errorMsg(err.Error()))
258 }
259 } else {
260 current = fn
261 }
262 for _, overload := range current.OverloadDecls() {
263 for _, macro := range parser.AllMacros {
264 if macro.Function() == current.Name() &&
265 macro.IsReceiverStyle() == overload.IsMemberFunction() &&
266 macro.ArgCount() == len(overload.ArgTypes()) {
267 errMsgs = append(errMsgs, overlappingMacroError(current.Name(), macro.ArgCount()))
268 }
269 }
270 if len(errMsgs) > 0 {
271 return errMsgs
272 }
273 }
274 e.declarations.SetFunction(current)
275 return errMsgs
276}
277
278func maybeMergeConstant(a *decls.VariableDecl, b *decls.VariableDecl) (*decls.VariableDecl, errorMsg) {
279 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