core.typed

Numeric types assigned to protocol method argument not recognized in inline defrecord implementation

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

In summary:

(tc/defprotocol IRandom
(-seed [this] :- tc/AnyInteger)
(-next-double [this] :- Double)
(-next-float [this] :- Float)
(-next-int
  [this] :- Integer
  [this limit :- Integer] :- Integer)
(-next-long [this] :- Long)
(-next-boolean [this] :- Boolean))
 
(tc/ann-record SeededRandom [seed :- tc/AnyInteger
                             rng :- java.util.Random])
 
#+clj
(defrecord SeededRandom [seed ^Random rng]
IRandom
(-seed [this] seed)
(-next-double [this] (.nextDouble rng))
(-next-float [this] (.nextFloat rng))
(-next-int [this] (.nextInt rng))
(-next-int [this limit] (.nextInt rng limit))
(-next-long [this] (.nextLong rng))
(-next-boolean [this] (.nextBoolean rng)))
 
 
-----------------
 
Type Error (cemerick/pprng.clj:43:27) Instance method java.util.Random/nextInt could not be applied to arguments:
 
 
Domains:
int
 
Arguments:
Object
 
Ranges:
int
 
with expected type:
(U Object nil)
 
in: (.nextInt rng limit)

-next-int's argument is typed as Integer, as confirmed by cf:

cemerick.pprng=> (tc/cf -next-int)
(Fn [IRandom -> java.lang.Integer] [IRandom java.lang.Integer -> java.lang.Integer])

To reproduce, clone pprng (note the WIP-typed-clojure branch). The project uses cljx, so you probably should run lein cljx auto while you're tinkering with the source so that the cljx transformation is run automatically in between your running (check-ns) (cljx doesn't generally require preprocessing, but TC seems to always reload definitions from disk and doesn't support REPL interactions based on in-file annotations.) Then:

$ lein with-profile TC repl
...
=> (require 'cemerick.pprng)
=> (in-ns 'cemerick.pprng)
=> (tc/check-ns)

Activity

Hide
Ambrose Bonnaire-Sergeant added a comment -
Show
Ambrose Bonnaire-Sergeant added a comment - Minimum failing case: https://gist.github.com/frenchy64/076d25450eed8f80aabe
Hide
Chas Emerick added a comment -
Show
Chas Emerick added a comment - Confirmed that this is fixed in 0.2.50, via https://github.com/clojure/core.typed/commit/203e0f2787fcb481a67e7e03c5a97a64f89e488b Thanks!

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: