Skip to main content

check_expr_with_environment

Function check_expr_with_environment 

Source
pub fn check_expr_with_environment(
    expr: &Expr,
    resolve_ident: &dyn Fn(&str) -> Option<Ty>,
    environment: &CheckingEnvironment,
    availability: MetadataAvailability,
) -> CheckingReport<Ty>
Expand description

Checks an expression using only catalog facts and lexical declarations.

Some(Ty::Any) declares an unresolved value; None permits function-name lookup. Closure bodies remain noncapturing. Unavailable host facts do not erase definite errors in children. No host emitter, constructor, or value operation is invoked. The returned type retains independently known result shapes even when diagnostics are present: logical results are Boolean and resolved casts retain their target. Invalid operations whose results cannot be inferred return Ty::Any, including within compound shapes. A known result type does not imply a valid expression or complete checking; callers must retain both diagnostic collections.

ยงExamples

use cel_parser::{AstContext, OpLookup, Parser, Ty};
use cel_parser::checking::*;
let expr = Parser::<AstContext>::new(OpLookup::new()).parse_str_ast("1i32 + 2i32").unwrap();
let env = CheckingBuilder::new().finish().unwrap();
let report = check_expr_with_environment(&expr, &|_| None, &env, MetadataAvailability::Complete);
assert_eq!(report.value, Ty::I32);
assert!(report.diagnostics.is_empty());
let expr = Parser::<AstContext>::new(OpLookup::new())
    .parse_str_ast("missing && true").unwrap();
let report = check_expr_with_environment(&expr, &|_| None, &env, MetadataAvailability::Complete);
assert_eq!(report.value, Ty::Bool);
assert_eq!(report.diagnostics.len(), 1);