clarkmcc / cel-rust

Common Expression Language interpreter written in Rust
https://crates.io/crates/cel-interpreter
MIT License
375 stars 21 forks source link

Support heterogeneous comparisons for numeric types #37

Closed fore5fire closed 8 months ago

fore5fire commented 8 months ago

According to the CEL spec, the CEL runtime supports implicit comparisons of different numeric types: See https://github.com/google/cel-spec/blob/master/doc/langdef.md#equality and https://github.com/google/cel-spec/blob/master/doc/langdef.md#numbers

From what I can tell, cel-rust doesn't have a separate checker step which would reject these implicit comparisons when static types are available, so I just implemented the spec's runtime behavior of always allowing them.

I also added functions to explicitly cast to ints and uints per https://github.com/google/cel-spec/blob/master/doc/langdef.md#list-of-standard-definitions