pub fn check_expr(
expr: &Expr,
resolve_ident: &dyn Fn(&str) -> Ty,
) -> (Ty, Vec<ParseError>)Expand description
Infers expr’s type against resolve_ident (looks up a free identifier’s declared type, or
Ty::Any if unknown — e.g. a bare CEL builtin name, or an adam-lang cell with no : type
annotation), returning the expression’s inferred type plus every type diagnostic found.
Uses an empty OpLookup; metadata-aware hosts use check_expr_with_type_resolver.
Checks every child, including closure bodies under parameter-local bindings.
Arrays require homogeneous complete shapes, tuples retain source order, and if joins
compatible branch types. Callable applications check parameter and result types.
Calls without metadata and free identifiers without declarations remain unresolved.
Registered function values retain concrete marker identity through aliases, rather than
using the alias’s spelling to select a signature. Builtin range expressions retain their
concrete range result, not their endpoint type.
- Complexity: O(n) in the number of nodes in
expr.
§Examples
use cel_parser::{Expr, ExprSpan, Literal, Ty};
use cel_parser::ty::check_expr;
let span = ExprSpan {
start: proc_macro2::Span::call_site(),
end: proc_macro2::Span::call_site(),
};
let expr = Expr::Literal {
value: Literal::I32(1),
span,
};
let (ty, diagnostics) = check_expr(&expr, &|_name| Ty::Any);
assert_eq!(ty, Ty::I32);
assert!(diagnostics.is_empty());