| @@ -1733,3 +1733,38 @@ |
| 1733 | 1733 | expression is still written verbatim to the fixture; feel-core handles it. |
| 1734 | 1734 | - **Coverage:** +3 fixture cases (0073 decisions 001–003, all `→ 2`). Suite |
| 1735 | 1735 | 2887 → 2890. |
| 1736 | + |
| 1737 | +## ADR-35: Typed formal parameters in function literals (DMN §10.3.2.13, rule 56) |
| 1738 | + |
| 1739 | +- **Context:** FEEL grammar rule 56 allows formal parameters to carry a type |
| 1740 | + annotation: `function(n: number, s: string) body`. ADR-23 introduced |
| 1741 | + `function(…)` literals with bare-name params only (rule 55 as if rule 56 |
| 1742 | + didn't exist). TCK `0092-feel-lambda` uses typed params throughout (e.g. |
| 1743 | + `function (a: number) 1 + a`), so bare-name-only params are a parse failure |
| 1744 | + for every 0092 case. |
| 1745 | +- **Decision:** Extend the grammar with a `FormalParam` rule replacing the |
| 1746 | + `Comma<Name>` in the two `FnDef` `TextualExpr` productions: |
| 1747 | + - **Grammar (`feel.lalrpop`):** `FormalParam: String = { <n:Name> => n, <n:Name> ":" InstanceType => n }`. The type annotation is parsed via the existing `InstanceType` nonterminal and then **discarded** — only the parameter name flows into `Expr::FnDef { params: Vec<String> }`. `Expr::FnDef` and the evaluator are unchanged. |
| 1748 | + - **LR(1):** After a `Name`, the one-token lookahead `:` shifts into the typed branch while `,`/`)` reduce to the bare branch — mirrors the `Arg` rule's decision. `build.rs` LALRPOP no-conflict gate verifies. |
| 1749 | + - **`Nb`/`Ep` clones:** `function(...)` literals do not appear in the bracket-free `NbPostfix`/`EpPostfix` chains; only `TextualExpr` needs the change. |
| 1750 | + - **Type enforcement:** This slice binds arguments by name only; arity is already `params.len()`. A typed annotation like `a: number` is parsed and dropped; no runtime type check is performed. This matches the spec semantics for this slice (the type system is advisory at the expression level). |
| 1751 | +- **Tests:** `typed_formal_params_parse_and_eval` and `typed_params_closure_and_currying` in `lib.rs` (positional, generic function type annotation, closure with typed param, three-level currying). Unlocks 0092 cases 001–014 and 016. |
| 1752 | +- **Consequence:** ADR-23's "typed parameters out of scope" deferral is now resolved. `function(a: number) 1 + a` parses and evaluates correctly. |
| 1753 | + |
| 1754 | +## ADR-36: First-class built-in function values (DMN §10.3.2.13.1) |
| 1755 | + |
| 1756 | +- **Context:** The FEEL spec (§10.3.2.13.1) defines invocation on any expression |
| 1757 | + (grammar rule 38: `expression parameters`). A built-in name used as a value |
| 1758 | + expression — e.g. `bkm(abs, sqrt)` where the BKM stores the function and calls |
| 1759 | + `fn1(-5) * fn2(25)` — must yield a callable function value rather than null. |
| 1760 | + TCK `0092-feel-lambda` cases 014 and 016 exercise this directly; case 017/018 |
| 1761 | + also rely on it (deferred, needs `sort/2`). |
| 1762 | +- **Decision:** |
| 1763 | + - **`function.rs`:** Add `Func::Builtin(String)` variant alongside `Closure` and `Foreign`. The string is the spec name (identical to what `builtins::call` dispatches on, including multi-word joined names like `"string length"`). `Clone` and `PartialEq` (builtins equal by name) added naturally. |
| 1764 | + - **`builtins.rs`:** Add `pub(crate) fn is_builtin(name: &str) -> bool` — a `matches!`-based membership predicate over the full built-in name set. Used by the evaluator to decide whether an unbound name is a built-in reference. |
| 1765 | + - **`eval.rs` `Expr::Var`:** If `ctx.get(name)` is `None` and `is_builtin(name)`, return `Func::Builtin(name)` as the value. A context binding still shadows a built-in (checked first), preserving ADR-23's precedence rule. |
| 1766 | + - **`eval.rs` `invoke`:** New `Func::Builtin(n)` arm dispatches to `builtins::call(n, args, env)`. Wrong-arity or type-error calls return `Some(Error)` from `call`, propagated as error-null; a missing name (impossible in practice) falls back to `Value::Error`. |
| 1767 | + - **`types.rs`:** `Func::Builtin` conforms to `Any` only (same as `Foreign` — arity is not statically known in the type lattice for this slice). |
| 1768 | +- **Consequence:** `keyword_phrase_builtin_parses_in_call_position` test updated: the multi-word name `"date and time"` out of call position now correctly returns a `Function` value rather than null (it was null only because the name was unbound; now it resolves to the built-in). Unlocks 0092 cases 014 and 016. |
| 1769 | +- **Tests:** `builtin_as_first_class_value` and `builtin_passed_as_argument_and_invoked` in `lib.rs`. |
| 1770 | +- **Coverage:** +16 fixture cases (0092 testCases 001–014 incl. 010_a, and 016). Suite 2880 → 2896. |