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

Method Resolve

interpreter/attributes.go:355–423  ·  view source on GitHub ↗

Resolve returns the resolved Attribute value given the Activation, or error if the Attribute variable is not found, or if its Qualifiers cannot be applied successfully. If the variable name cannot be found as an Activation variable or in the TypeProvider as a type, then the result is `nil`, `error`

(vars Activation)

Source from the content-addressed store, hash-verified

353// a type, then the result is `nil`, `error` with the error indicating the name of the first
354// variable searched as missing.
355func (a *absoluteAttribute) Resolve(vars Activation) (any, error) {
356 // unwrap any local activations to ensure that we reach the variables provided as input
357 // to the expression in the event that we need to disambiguate between global and local
358 // variables.
359 //
360 // Presently, only dynamic and constant slot activations created during comprehensions
361 // support 'unwrapping', which is consistent with how local variables are introduced into CEL.
362 var inputVars Activation
363 if a.disambiguateNames {
364 inputVars = vars
365 wrapped, ok := inputVars.(activationWrapper)
366 for ok {
367 next := wrapped.Unwrap()
368 if next == nil {
369 break
370 }
371 inputVars = next
372 wrapped, ok = inputVars.(activationWrapper)
373 }
374 }
375 for _, nm := range a.namespaceNames {
376 // If the variable is found, process it. Otherwise, wait until the checks to
377 // determine whether the type is unknown before returning.
378 v := vars
379 if a.disambiguateNames {
380 v = inputVars
381 }
382 obj, found := v.ResolveName(nm)
383 if found {
384 if celErr, ok := obj.(*types.Err); ok {
385 return nil, celErr
386 }
387 _, isUnknown := obj.(*types.Unknown)
388 if isUnknown {
389 return obj, nil
390 }
391 if len(a.qualifiers) == 0 {
392 return obj, nil
393 }
394 obj, isOpt, err := applyQualifiers(v, obj, a.qualifiers)
395 if err != nil {
396 return nil, err
397 }
398 if isOpt {
399 val := a.adapter.NativeToValue(obj)
400 if types.IsUnknown(val) {
401 return val, nil
402 }
403 return types.OptionalOf(val), nil
404 }
405 return obj, nil
406 }
407 // Attempt to resolve the qualified type name if the name is not a variable identifier.
408 typ, found := a.provider.FindIdent(nm)
409 if found {
410 if len(a.qualifiers) == 0 {
411 return typ, nil
412 }

Callers

nothing calls this directly

Calls 9

IsUnknownFunction · 0.92
OptionalOfFunction · 0.92
applyQualifiersFunction · 0.85
missingAttributeFunction · 0.85
UnwrapMethod · 0.65
ResolveNameMethod · 0.65
NativeToValueMethod · 0.65
FindIdentMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected