Skip to content

Commit

Permalink
Issue 284: Improve multi-child negation exception (#488)
Browse files Browse the repository at this point in the history
Issue 284: Include faulty expression in compilation exception for multi-child negations
  • Loading branch information
WilliamParker committed Jun 20, 2023
1 parent 9bcf516 commit a22cba9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This is a history of changes to clara-rules.
* extract clara.rules.compiler/compile-test-handler from clara.rules.compiler/compile-test
* add support for `env` inside of test expressions
* use `.clj_kondo` extension for clj-kondo hook code for better tool compatibility (clj-kondo support now requires clj-kondo 2022.04.25 or higher)
* Include the invalid constraint in the exception thrown at session compilation time when negations have multiple children. See [Issue 284](https://github.com/cerner/clara-rules/issues/284).

# 0.22.1
* fix incorrent lint warning triggered when this binding is not used in clj-kondo hooks
Expand Down
2 changes: 1 addition & 1 deletion src/main/clojure/clara/rules/compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@
child (first children)]

(when (not= 1 (count children))
(throw (RuntimeException. "Negation must have only one child.")))
(throw (ex-info "Negation must have only one child." {:illegal-negation expression})))

(condp = (expr-type child)

Expand Down
12 changes: 12 additions & 0 deletions src/test/clojure/clara/test_rules.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2424,3 +2424,15 @@
:name :clara.rules.test-rules-data/is-cold-and-windy-data
:lhs []
:rhs '(println "I have no meaning outside of this test")}))) {})))

(deftest test-negation-multiple-children-exception
(let [not-rule (dsl/parse-rule [[:not
[Hot (= ?t temperature)]
[Temperature (> temperature 0)]]]
(insert! (->LousyWeather)))]
(assert-ex-data
{:illegal-negation [:not {:type clara.rules.testfacts.Hot
:constraints ['(= ?t temperature)]}
{:type clara.rules.testfacts.Temperature
:constraints ['(> temperature 0)]}]}
(mk-session [not-rule] :cache false))))

0 comments on commit a22cba9

Please sign in to comment.