Log
634f19df41a9
feat(core): value-invocation of a literal callee → null (ADR-38)
public
feat(core): value-invocation of a literal callee → null (ADR-38)
Adds `Expr::Invoke(Box<Expr>, CallArgs)` as the AST node for invoking a
literal callee such as `null()`, `123()`, `"abs"(-1)`, `@"2023-11-11"()`
or `true()`/`false()`. Distinct from `Expr::FnCall` (by-name dispatch) so
named built-in calls are completely unaffected.
Grammar: a new `Invocable` nonterminal covers the six literal forms and
feeds two new `Postfix` productions `<e:Invocable> "(" … ")"` that build
`Invoke` nodes. `Name` is excluded from `Invocable` so the `FnCall` path
keeps its monopoly on named dispatch.
Eval: the `Invoke` arm evaluates the callee; a `Value::Function` is
invoked normally, any other value produces `Value::Error` (→ null at the
lenient boundary), satisfying DMN §10.3.2.13.2 "invoking a non-function".
Tests: `invoke_non_function_yields_null` in `lib.rs::function_tests`
covers all eight 1131 expression shapes plus a regression check that
`abs(-1)` still routes through the unmodified `FnCall` path.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
modified
crates/feel-core/src/ast.rs
+12 −0
@@ -41,6 +41,13 @@
41 41 /// named arguments. Dispatch (context function / built-in / host registry) is 42 42 /// resolved at evaluation (ADR-23). 43 43 FnCall(String , CallArgs), 44 + /// Invocation of a *value* callee, e.g. `123()`, `"abs"(-1)`, `null()` (ADR-38). 45 + /// Distinct from [`FnCall`]: here the callee expression is evaluated first; if it 46 + /// is not a [`Value::Function`] the call yields null (DMN §10.3.2.13.2). The 47 + /// grammar only produces this for literal callees (never for a `Name`), so today 48 + /// every `Invoke` evaluates to null; the function branch is the correct general 49 + /// semantics should the callee grammar widen in future. 50 + Invoke(Box < Expr> , CallArgs), 44 51 /// A FEEL function literal `function(a, b) body` — an anonymous closure that 45 52 /// captures the scope it is defined in (ADR-23). `params` are the formal 46 53 /// parameter names in order.
@@ -373,6 +380,11 @@
373 380 & & args.positional.iter().all(Expr::is_clock_free) 374 381 & & args.named.iter().all(| (_, e)| e.is_clock_free()) 375 382 } 383 + Expr::Invoke(callee, args) = > { 384 + callee.is_clock_free() 385 + & & args.positional.iter().all(Expr::is_clock_free) 386 + & & args.named.iter().all(| (_, e)| e.is_clock_free()) 387 + } 376 388 Expr::FnDef { body, .. } = > body.is_clock_free(), 377 389 Expr::Neg(e) | Expr::Not(e) | Expr::UnaryTestVal(_, e) = > e.is_clock_free(), 378 390 Expr::Arith(_, a, b) | Expr::Compare(_, a, b) | Expr::And(a, b) | Expr::Or(a, b) = > {
modified
crates/feel-core/src/eval.rs
+11 −0
@@ -126,6 +126,17 @@
126 126 }) 127 127 .into_value()), 128 128 Expr::FnCall(name, args) = > self .eval_call(name, args, ctx), 129 + // Value-invocation: evaluate the callee, invoke if it is a function, else 130 + // error-null (DMN §10.3.2.13.2; ADR-38). Args are skipped for non-functions 131 + // — FEEL has no side-effects, so this is observably identical to evaluating 132 + // them. 133 + Expr::Invoke(callee, args) = > match self .eval(callee, ctx)? .forced() { 134 + Value::Function(f) = > { 135 + let a = self .eval_args(args, ctx)? ; 136 + self .invoke(& f, a) 137 + } 138 + _ = > Ok (Value::Error), 139 + }, 129 140 130 141 // --- arithmetic --- 131 142 // Operands are `forced()` so a lazy host value is materialised before
modified
crates/feel-core/src/feel.lalrpop
+19 −0
@@ -216,7 +216,26 @@
216 216 <e:Postfix> "[" <idx:Expr> "]" => Expr::Filter(Box::new(e), Box::new(idx)), 217 217 <n:Name> "(" ")" => Expr::FnCall(n, CallArgs::default()), 218 218 <n:Name> "(" <a:Comma<Arg>> ")" => Expr::FnCall(n, callargs_from(a)), 219 + // Value-invocation of a *literal* callee (DMN §10.3.2.13.2, ADR-38). `Name` is 220 + // excluded so named calls stay on the FnCall path (builtin/host/scope dispatch). 221 + // LR(1)-clean: each alternative reduces to `Invocable` on a lookahead other than 222 + // `(`, or shifts into the call on `(`; `Name` is in `Primary` not `Invocable`, so 223 + // this production never competes with `Name "(" … ")"`. 224 + <e:Invocable> "(" ")" => Expr::Invoke(Box::new(e), CallArgs::default()), 225 + <e:Invocable> "(" <a:Comma<Arg>> ")" => Expr::Invoke(Box::new(e), callargs_from(a)), 219 226 Primary, 227 +}; 228 + 229 +// Literal expressions that may appear as a value-invocation callee (ADR-38). Every 230 +// element here is a non-function, so `Invoke` always evaluates to null (DMN 231 +// §10.3.2.13.2). `Name` is deliberately absent — named calls use `FnCall`. 232 +Invocable: Expr = { 233 + Num => Expr::Number(<>), 234 + Str => Expr::Str(<>), 235 + TemporalLit => Expr::TemporalLit(<>), 236 + "true" => Expr::Bool(true), 237 + "false" => Expr::Bool(false), 238 + "null" => Expr::Null, 220 239 }; 221 240 222 241 // One call argument: positional (`expr`) or named (`name: expr`). Both start with
modified
crates/feel-core/src/lib.rs
+19 −0
@@ -2560,6 +2560,25 @@
2560 2560 ); 2561 2561 } 2562 2562 2563 + // --- value-invocation of a non-function → null (ADR-38, 1131) ----------- // 2564 + 2565 + #[ test ] 2566 + fn invoke_non_function_yields_null () { 2567 + // unknown name → error-null (FnCall path, unchanged) 2568 + assert_eq! (ev(" non_existing_function() " ), Value::Null); 2569 + // null, string, number, boolean, date — all non-functions → null 2570 + assert_eq! (ev(" null() " ), Value::Null); 2571 + assert_eq! (ev(" \" some_func \" () " ), Value::Null); 2572 + assert_eq! (ev(" \" abs \" (-1) " ), Value::Null); 2573 + assert_eq! (ev(" 123() " ), Value::Null); 2574 + assert_eq! (ev(" true() " ), Value::Null); 2575 + assert_eq! (ev(" false() " ), Value::Null); 2576 + assert_eq! (ev(" @ \" 2023-11-11 \" () " ), Value::Null); 2577 + // Named calls to built-ins must be unaffected (FnCall path still works). 2578 + assert_eq! (ev(" abs(-1) " ), Value::Number(1.0 )); 2579 + assert_eq! (ev(" abs(n: -2) " ), Value::Number(2.0 )); 2580 + } 2581 + 2563 2582 // --- host callables (ForeignFunction) ------------------------------------ // 2564 2583 2565 2584 /// A host function that sums all of its numeric arguments (positional + named),