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

Method checkCall

checker/checker.go:259–323  ·  view source on GitHub ↗
(e ast.Expr)

Source from the content-addressed store, hash-verified

257}
258
259func (c *checker) checkCall(e ast.Expr) {
260 // Note: similar logic exists within the `interpreter/planner.go`. If making changes here
261 // please consider the impact on planner.go and consolidate implementations or mirror code
262 // as appropriate.
263 call := e.AsCall()
264 fnName := call.FunctionName()
265 if fnName == operators.OptSelect {
266 c.checkOptSelect(e)
267 return
268 }
269
270 args := call.Args()
271 // Traverse arguments.
272 for _, arg := range args {
273 c.check(arg)
274 }
275
276 // Regular static call with simple name.
277 if !call.IsMemberFunction() {
278 // Check for the existence of the function.
279 fn := c.env.lookupFunction(fnName)
280 if fn == nil {
281 c.errors.undeclaredReference(e.ID(), c.location(e), c.env.container.Name(), fnName)
282 c.setType(e, types.ErrorType)
283 return
284 }
285 // Overwrite the function name with its fully qualified resolved name.
286 e.SetKindCase(c.NewCall(e.ID(), fn.Name(), args...))
287 // Check to see whether the overload resolves.
288 c.resolveOverloadOrError(e, fn, nil, args)
289 return
290 }
291
292 // If a receiver 'target' is present, it may either be a receiver function, or a namespaced
293 // function, but not both. Given a.b.c() either a.b.c is a function or c is a function with
294 // target a.b.
295 //
296 // Check whether the target is a namespaced function name.
297 target := call.Target()
298 qualifiedPrefix, maybeQualified := containers.ToQualifiedName(target)
299 if maybeQualified {
300 maybeQualifiedName := qualifiedPrefix + "." + fnName
301 fn := c.env.lookupFunction(maybeQualifiedName)
302 if fn != nil {
303 // The function name is namespaced and so preserving the target operand would
304 // be an inaccurate representation of the desired evaluation behavior.
305 // Overwrite with fully-qualified resolved function name sans receiver target.
306 e.SetKindCase(c.NewCall(e.ID(), fn.Name(), args...))
307 c.resolveOverloadOrError(e, fn, nil, args)
308 return
309 }
310 }
311
312 // Regular instance call.
313 c.check(target)
314 fn := c.env.lookupFunction(fnName)
315 // Function found, attempt overload resolution.
316 if fn != nil {

Callers 1

checkMethod · 0.95

Calls 15

checkOptSelectMethod · 0.95
checkMethod · 0.95
locationMethod · 0.95
setTypeMethod · 0.95
ToQualifiedNameFunction · 0.92
lookupFunctionMethod · 0.80
undeclaredReferenceMethod · 0.80
AsCallMethod · 0.65
FunctionNameMethod · 0.65
ArgsMethod · 0.65
IsMemberFunctionMethod · 0.65

Tested by

no test coverage detected