Public repository: timo / feel

Reader

An interpreter of FEEL, written in Rust, with integrations for PostgreSQL, WASM, Lua, and Python.

feat(core): range properties + instance of for comparison-test value

public

feat(core): range properties + instance of for comparison-test value

§10.3.2.7 ("Ranges", Table 42) calls the single-endpoint-operator form
`(< 10)` / `(>= 10)` / … "a typed instance of the range type": it has the
four range properties and conforms to `range<T>`. ADR-32 had shipped it as
the opaque `Value::UnaryTestVal` but declared it typeless with no member
access — a §10.3.2.7 deviation. Add a `Value::UnaryTestVal` arm to both
`member_access` (eval.rs) and `value_conforms_to` (types.rs), derived from
the boxed `{ op, endpoint }` per Table 42: the operator's missing endpoint
is `null` + not included, the present endpoint's inclusivity follows the
operator, and the present endpoint must conform to `T` (the undefined side
vacuous, like an unbounded `Range` endpoint).

Equality stays opaque (ADR-32, unchanged): `(=10).start`/`.end` are `10`/`10`
yet `(=10) ≠ [10..10]`, and `(<10) instance of range<number>` is true yet
`(<10) = (..10)` is false — projections and equality are independent facets,
exactly as TCK 0068 + 0074 jointly demand. `Value` stays 40 bytes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Changeseta7972edc7c10098a1053521d728f275b851b1996
Author (claimed)Timo Stolz <timo.stolz@gmail.com>,
Parents0821dc21db3a
Children
Pushlog
by timo via ssh

modified crates/feel-core/src/eval.rs +29 −0

@@ -957,6 +957,35 @@
957957
             "end included" => Value::Boolean(r.end.is_some() && !r.end_open),
958958
             _ => Value::Null,
959959
         },
960
+        // A comparison-test value `(< 10)` (ADR-32) is a range-typed value for the
961
+        // purpose of these projections (DMN §10.3.2.7 / Table 42, TCK 0074
962
+        // `range_006`–`011`): the single-endpoint-operator form leaves the *other*
963
+        // endpoint **undefined** (property `null`, never `included`), while the
964
+        // present endpoint's inclusivity follows the operator (`<=`/`>=`/`=` are
965
+        // included, the strict `<`/`>`/`!=` are not). Only these projections are
966
+        // range-shaped — its *equality* stays OPAQUE (ADR-32, `feel_equal_depth`):
967
+        // `(=10).start`/`.end` are `10`/`10` even though `(=10) ≠ [10..10]`.
968
+        Value::UnaryTestVal(u) => {
969
+            use crate::ast::CmpOp;
970
+            let e = &u.endpoint;
971
+            // (start, start included, end, end included) per Table 42.
972
+            let (start, start_incl, end, end_incl): (Option<&Value>, bool, Option<&Value>, bool) =
973
+                match u.op {
974
+                    CmpOp::Lt => (None, false, Some(e), false),
975
+                    CmpOp::Le => (None, false, Some(e), true),
976
+                    CmpOp::Gt => (Some(e), false, None, false),
977
+                    CmpOp::Ge => (Some(e), true, None, false),
978
+                    CmpOp::Eq => (Some(e), true, Some(e), true),
979
+                    CmpOp::Ne => (Some(e), false, Some(e), false),
980
+                };
981
+            match name {
982
+                "start" => start.cloned().unwrap_or(Value::Null),
983
+                "end" => end.cloned().unwrap_or(Value::Null),
984
+                "start included" => Value::Boolean(start_incl),
985
+                "end included" => Value::Boolean(end_incl),
986
+                _ => Value::Null,
987
+            }
988
+        }
960989
         v if temporal::is_temporal(&v) => temporal::get_property(&v, name),
961990
         _ => Value::Error,
962991
     }

modified crates/feel-core/src/types.rs +5 −0

@@ -36,6 +36,11 @@
3636
                 r.start.as_ref().is_none_or(|s| conforms_nested(s, elem))
3737
                     && r.end.as_ref().is_none_or(|e| conforms_nested(e, elem))
3838
             }
39
+            // A comparison-test value `(< 10)` is "a typed instance of the range
40
+            // type" (DMN §10.3.2.7), so `(< 10) instance of range<number>` is true.
41
+            // Its single present endpoint must conform to `T`; the undefined side
42
+            // conforms vacuously, exactly like an unbounded `Range` endpoint.
43
+            Value::UnaryTestVal(u) => conforms_nested(&u.endpoint, elem),
3944
             _ => false,
4045
         },
4146
         FeelType::Number => matches!(v, Value::Number(_)),