datalog: aggregate arg validators (259/259)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 28s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 28s
Bug: dl-eval-aggregate accepted non-variable agg-vars and non- literal goals silently, producing weird/incorrect counts: - `count(N, 5, p(X))` would compute count over the single constant 5 (always 1), ignoring p entirely. - `count(N, X, 42)` would crash with "unknown body-literal shape" at saturation time rather than at rule-add time. Fix: dl-eval-aggregate now validates up front that the second arg is a variable (the value to aggregate) and the third arg is a positive literal (the goal). Errors are descriptive and include the offending argument. 2 new aggregate tests.
This commit is contained in:
@@ -244,6 +244,18 @@
|
||||
{:U (quote carol) :N 0}))
|
||||
|
||||
;; Stratification: recursion through aggregation is rejected.
|
||||
;; Aggregate validates that second arg is a variable.
|
||||
(dl-at-test! "agg second arg must be var"
|
||||
(dl-at-throws?
|
||||
(fn () (dl-eval "p(1). q(N) :- count(N, 5, p(X))." "?- q(N).")))
|
||||
true)
|
||||
|
||||
;; Aggregate validates that third arg is a positive literal.
|
||||
(dl-at-test! "agg third arg must be a literal"
|
||||
(dl-at-throws?
|
||||
(fn () (dl-eval "p(1). q(N) :- count(N, X, 42)." "?- q(N).")))
|
||||
true)
|
||||
|
||||
;; Indirect recursion through aggregation also rejected.
|
||||
;; q -> r (via positive lit), r -> q (via aggregate body).
|
||||
;; The aggregate edge counts as negation for stratification.
|
||||
|
||||
Reference in New Issue
Block a user