Tensegritics / Tensegritics/ClojureDart
Calling predicates on negative numeric literals sometimes produce compilation errors
Nobody has claimed this yet.
- Dominant language
- Clojure
- Stars
- 1.6k
- Forks
- 119
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
When a numeric predicate is applied to a negative literal (odd? -1) and paired with something like an if form, ClojureDart produces compilation errors.
Failing test to recreate the problem:
(deftest test-negative-preds
; These pass
(is (odd? 5))
(is (even? 4))
(is (odd? -5))
(is (even? -4))
(is (not (odd? 4)))
(is (not (even? 5)))
(is (odd? -5))
(is (even? -4))
; These fail to compile (not expands to an "if" form)
(is (not (odd? -4)))
(is (not (even? -5)))
)
Console output on ./run-tests
00:14 +1 -13: loading test/cljd-out/cljd/test-clojure/predicates_test.dart [E]
Failed to load "test/cljd-out/cljd/test-clojure/predicates_test.dart":
test/cljd-out/cljd/test-clojure/predicates_test.dart:1381:66: Error: The operator 'unary-' isn't defined for the class 'bool'.
Try correcting the operator to an existing operator, or defining a 'unary-' operator.
final dc.dynamic values$8915_$AUTO_$9=(lcoc_core.list.$_invoke$1(-4.isOdd, ));
^
test/cljd-out/cljd/test-clojure/predicates_test.dart:1432:67: Error: The operator 'unary-' isn't defined for the class 'bool'.
Try correcting the operator to an existing operator, or defining a 'unary-' operator.
final dc.dynamic values$8915_$AUTO_$10=(lcoc_core.list.$_invoke$1(-5.isEven, ));
^
Does your problem persist after clj -M:cljd clean && flutter clean?
No cljd clean command on ClojureDart repo
To Reproduce
Steps to reproduce the behavior:
- Add the
test-negative-predstest above to a test file in the ClojureDart repo - Execute
./run-tests - The error above appears in console output
Expected behavior
All tests above pass with no compilation errors
Additional context
This seems to only happen when working with negative numeric literals. If a negative is assigned to a symbol, for example, everything seems to work fine.
Additionally, as demonstrated by the tests, the problem only presents itself when paired with something like an if; executing something like (odd? -5) on its own doesn't appear to cause any issues.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied test-negative-preds reproduction and run ./run-tests, then inspect the compiler path that handles negative numeric literals when they appear inside not or if forms. Compare the generated test/cljd-out/cljd/test-clojure/predicates_test.dart around the reported unary- errors with the cases that already compile. Done means all listed predicate assertions compile and pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure, dart, flutter
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100