datalog: comparison ops require same-type operands
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 28s

Type-mixed comparisons were silently inconsistent:

  <("hello", 5)  =>  no result, no error  (silent false)
  <(a, 5)        =>  raises "Expected number, got symbol"

Both should fail loudly with a comprehensible message. Added
dl-compare-typeok?: <, <=, >, >= now require both operands to share
a primitive type (both numbers or both strings) and raise a clear
"comparison <op> requires same-type operands" error otherwise.

`!=` is exempted because it's the polymorphic inequality test
built on dl-tuple-equal? — cross-type pairs are legitimately unequal
and the existing semantics for that case match user intuition.

2 new regression tests; conformance 267/267.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-11 08:07:40 +00:00
parent ba60db2eef
commit 917ffe5ccc
5 changed files with 58 additions and 8 deletions

View File

@@ -15,7 +15,7 @@ for rose-ash data (e.g. federation graph, content relationships).
## Status (rolling)
`bash lib/datalog/conformance.sh`**265/265 across 11 suites**
`bash lib/datalog/conformance.sh`**267/267 across 11 suites**
(tokenize, parse, unify, eval, builtins, semi_naive, negation, aggregates,
api, magic, demo). Source is ~3100 LOC, tests ~2900 LOC, public API
documented in `lib/datalog/datalog.sx`.
@@ -320,6 +320,15 @@ large graphs.
_Newest first._
- 2026-05-11 — Type-mixed comparisons were silently inconsistent:
`<(X, 5)` with `X` bound to a string returned `()` (no result, no
error), while `X` bound to a symbol raised "Expected number, got
symbol". Both should fail loudly. Added `dl-compare-typeok?` —
`<`, `<=`, `>`, `>=` now require both operands to share a primitive
type (both numbers or both strings) and raise otherwise. `!=` is
exempted since it's a polymorphic inequality test built on
`dl-tuple-equal?`. 2 new regression tests; 267/267.
- 2026-05-11 — Body literal shape validation in
`dl-rule-check-safety`: a dict that isn't `{:neg ...}` (e.g. typo'd
`{:negs ...}`) used to silently fall through every dispatch clause,