core.typed

(fn [x] (map inc [x 2 3])) errors with "Could not apply dotted function"

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
  • Environment:
    [org.clojure/core.typed "0.1.17"]

Description

type-examples.core> (t/cf (t/ann-form (fn [x] (map inc [x 2 3])) [Number -> (clojure.lang.LazySeq Number)]))
Type Error (type-examples.core:1:50) Could not apply dotted function (All [v0 v1 v2 ...] (Fn [(Fn [v1 v2 ... v2 -> v0]) (U nil (Seqable v1)) (U nil (Seqable v2)) ... v2 -> (LazySeq v0)])) to arguments [(Fn [t/AnyInteger -> t/AnyInteger] [Number -> Number]) [Number (Value 2) (Value 3)]]
in: (clojure.core/map clojure.core/inc [x 2 3])

Activity

Hide
Ambrose Bonnaire-Sergeant added a comment -

This is a legitimate issue, now fixed on my machine. I must have had a long night when I was porting the Typed Racket constraint generation!

Thanks for the report Alan!

Show
Ambrose Bonnaire-Sergeant added a comment - This is a legitimate issue, now fixed on my machine. I must have had a long night when I was porting the Typed Racket constraint generation! Thanks for the report Alan!
Hide
Ambrose Bonnaire-Sergeant added a comment -

This is not a limitation of LTI.

Show
Ambrose Bonnaire-Sergeant added a comment - This is not a limitation of LTI.
Hide
Ambrose Bonnaire-Sergeant added a comment - - edited

Unfortunately it seems the type inference isn't good enough to deal with (map f coll), where f has more than one arity and coll triggers one other than the most specific.

eg.
(map + [1])
=> (LazySeq AnyInteger)

(map + [1.1]
=> constraint gen error

Workaround: assign f a less accurate type, probably one with just a single arity.

eg.
(map (ann-form + [Number -> Number]) [1.1])
=> (LazySeq Number)

The particular issue here can be fixed with:

(cf (fn [x]
(map (ann-form inc [Number -> Number])
[x 2 3]))
[Number -> (clojure.lang.LazySeq Number)])

Show
Ambrose Bonnaire-Sergeant added a comment - - edited Unfortunately it seems the type inference isn't good enough to deal with (map f coll), where f has more than one arity and coll triggers one other than the most specific. eg. (map + [1]) => (LazySeq AnyInteger) (map + [1.1] => constraint gen error Workaround: assign f a less accurate type, probably one with just a single arity. eg. (map (ann-form + [Number -> Number]) [1.1]) => (LazySeq Number) The particular issue here can be fixed with: (cf (fn [x] (map (ann-form inc [Number -> Number]) [x 2 3])) [Number -> (clojure.lang.LazySeq Number)])

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: