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)
| 324 | // a type, then the result is `nil`, `error` with the error indicating the name of the first |
| 325 | // variable searched as missing. |
| 326 | func (a *absoluteAttribute) Resolve(vars Activation) (any, error) { |
| 327 | // unwrap any local activations to ensure that we reach the variables provided as input |
| 328 | // to the expression in the event that we need to disambiguate between global and local |
| 329 | // variables. |
| 330 | // |
| 331 | // Presently, only dynamic and constant slot activations created during comprehensions |
| 332 | // support 'unwrapping', which is consistent with how local variables are introduced into CEL. |
| 333 | var inputVars Activation |
| 334 | if a.disambiguateNames { |
| 335 | inputVars = vars |
| 336 | wrapped, ok := inputVars.(activationWrapper) |
| 337 | for ok { |
| 338 | inputVars = wrapped.Unwrap() |
| 339 | wrapped, ok = inputVars.(activationWrapper) |
| 340 | } |
| 341 | } |
| 342 | for _, nm := range a.namespaceNames { |
| 343 | // If the variable is found, process it. Otherwise, wait until the checks to |
| 344 | // determine whether the type is unknown before returning. |
| 345 | v := vars |
| 346 | if a.disambiguateNames { |
| 347 | v = inputVars |
| 348 | } |
| 349 | obj, found := v.ResolveName(nm) |
| 350 | if found { |
| 351 | if celErr, ok := obj.(*types.Err); ok { |
| 352 | return nil, celErr |
| 353 | } |
| 354 | obj, isOpt, err := applyQualifiers(v, obj, a.qualifiers) |
| 355 | if err != nil { |
| 356 | return nil, err |
| 357 | } |
| 358 | if isOpt { |
| 359 | val := a.adapter.NativeToValue(obj) |
| 360 | if types.IsUnknown(val) { |
| 361 | return val, nil |
| 362 | } |
| 363 | return types.OptionalOf(val), nil |
| 364 | } |
| 365 | return obj, nil |
| 366 | } |
| 367 | // Attempt to resolve the qualified type name if the name is not a variable identifier. |
| 368 | typ, found := a.provider.FindIdent(nm) |
| 369 | if found { |
| 370 | if len(a.qualifiers) == 0 { |
| 371 | return typ, nil |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | var attrNames strings.Builder |
| 376 | for i, nm := range a.namespaceNames { |
| 377 | if i != 0 { |
| 378 | attrNames.WriteString(", ") |
| 379 | } |
| 380 | attrNames.WriteString(nm) |
| 381 | } |
| 382 | return nil, missingAttribute(attrNames.String()) |
| 383 | } |
nothing calls this directly
no test coverage detected