| @@ -766,8 +766,59 @@ |
| 766 | 766 | data (`collect_context_keys`) so a filter referencing an element's entries fits the |
| 767 | 767 | slice. |
| 768 | 768 | - **Consequence:** §10.3.2.5 is complete. Still out of scope (documented): unary tests |
| 769 | | - (the non-interval `in` forms), `instance of`, and `sort`/matching-`list replace` (need a |
| 769 | + (the non-interval `in` forms), and `sort`/matching-`list replace` (need a |
| 770 | 770 | function-valued comparator — feasible now that function values exist, ADR-23). |
| 771 | + |
| 772 | +## ADR-26: `instance of` type predicate — type lattice & structural conformance (DMN §10.3.2.9) |
| 773 | + |
| 774 | +- **Context:** `instance of` (`value instance of type`, grammar rule 51) was the last |
| 775 | + comparison-level operator missing from feel-core, and the only one needing a notion the |
| 776 | + engine lacked entirely: a *type*. DMN-TCK `0070-feel-instance-of` exercises it across |
| 777 | + every value kind, against built-in/`Any`/`Null` types and inline generics. |
| 778 | +- **Decision:** add a minimal type lattice **L** as `ast::FeelType` (the primitive nodes, |
| 779 | + `Any`/`Null`, the parameterised `list`/`range`/`context`/`function` nodes, and an |
| 780 | + `Unknown` node for unmappable type names), and one AST node `Expr::InstanceOf(Box<Expr>, |
| 781 | + FeelType)`. The `FeelType` is resolved **at parse time** — it carries no runtime data. |
| 782 | + - **Type grammar (spec rule 52), restricted & LR(1)-clean:** the right operand parses |
| 783 | + via a dedicated `InstanceType` sub-grammar reachable only after `instance of` — a |
| 784 | + named type, `list<T>`/`range<T>`, `context<k: T, …>`, or `function<…> -> T`. The |
| 785 | + field-vs-type choice inside `<…>` reuses the same one-token (`:`) lookahead the call |
| 786 | + `Arg` rule already uses, so lalrpop builds conflict-free (the `build.rs` gate enforces |
| 787 | + it). An unmappable name — a model `itemDefinition` type this standalone engine can't |
| 788 | + resolve, a typo, or a bare `list`/`context` that "requires parameters" — becomes |
| 789 | + `FeelType::Unknown`, so e.g. `123 instance of list` evaluates to `null` (the spec |
| 790 | + result) rather than failing to parse. |
| 791 | + - **`instance of` lexing (no new reserved words):** `instance` and `of` are **not** |
| 792 | + reserved — FEEL names may contain them (`year of birth`, the `day of week` built-in), |
| 793 | + so reserving `of` would break those. Instead a pre-pass ([`lexer::mark_instance_of`]) |
| 794 | + fuses only the adjacent `instance` `of` pair into one `Tok::InstanceOf` operator |
| 795 | + *before* name-joining; a lone `instance`/`of` stays an ordinary name-word. The |
| 796 | + function-type arrow `->` is a new `logos` token (it only ever appears literally in a |
| 797 | + function type, so maximal-munch keeps `-`/`>` intact elsewhere). The three |
| 798 | + keyword-containing temporal type names (`date and time`, `years and months duration`, |
| 799 | + `days and time duration`) are now joined into a single `Name` **wherever they occur** |
| 800 | + (previously only in call position) so they read as type names too; they are reserved |
| 801 | + FEEL type/constructor names, so the only behaviour lost is logical-`and` of variables |
| 802 | + literally named `date`/`time`/… — not meaningful FEEL. |
| 803 | + - **Semantics — structural conformance (`types::value_conforms_to`):** rather than a |
| 804 | + canonical `type(value)` + lattice `conforms_to` with joins, the value is checked |
| 805 | + against the target type structurally (equivalent for every FEEL shape, less code). |
| 806 | + Top level: an unmappable type → `null`; a `null`/error value is an instance only of |
| 807 | + `Null`; otherwise the value must conform. A `null` nested in a list element or |
| 808 | + context field has type `Null` and `Null <: T`, so it conforms — which is why |
| 809 | + `{a: null} instance of context<a: string>` is `true` while top-level `null instance |
| 810 | + of string` is `false`. `context` conformance allows extra value keys (n ≥ m); |
| 811 | + functions check arity only (untyped closures map to `(Any, …) -> Any`). |
| 812 | +- **Tests:** ingested DMN-TCK `0070-feel-instance-of` (119 self-contained cases; the |
| 813 | + slice detector now splits on `instance of` and validates the type's words against a |
| 814 | + built-in whitelist). The 23 skipped cases reference model `itemDefinition` types (no |
| 815 | + type registry exists — out of scope) or are function-literal *values* (function literals |
| 816 | + aren't ingested generally); both are covered by feel-core unit tests, alongside the spec |
| 817 | + Table 62 examples and the nested-null/`Null` edges. |
| 818 | +- **Consequence:** §10.3.2.9 type-checking is supported for the self-contained type |
| 819 | + language. Still out of scope (documented): model-defined `itemDefinition` types (need a |
| 820 | + type registry threaded from the embedder), and `range` *values* (no first-class range |
| 821 | + value exists, so `instance of range<T>` is always `false`). |
| 771 | 822 | |
| 772 | 823 | ## Adding a wrapper — the host-binding contract |
| 773 | 824 | |