Skip to content

Calling predicates on negative numeric literals sometimes produce compilation errors #343

@brandoncorrea

Description

@brandoncorrea

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:

  1. Add the test-negative-preds test above to a test file in the ClojureDart repo
  2. Execute ./run-tests
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions