core.typed

Apply doesn't work with dotted arguments

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

This code:

(t/ann foo (All [x y ...] [[y ... y -> x] -> [y ... y -> x]]))
(defn foo
  "Doesn't do anything useful."
  [f]
  (let [mem (memoize (fn [& args] #(apply f args)))]
    (fn [& args]
      ((apply mem args)))))

On type-check throws this exception:

AssertionError Assert failed: (not (some :drest (:types fin)))  clojure.core.typed.check/relevant-Fns (check.clj:2661)

I'm using core.typed version 0.2.36.

Activity

Hide
Ambrose Bonnaire-Sergeant added a comment -

I suspect minimal case is:

(cf (fn [f & args] (apply f args)) (All [b ...] [[b ... b -> Any] b ... b -> Any]))
Show
Ambrose Bonnaire-Sergeant added a comment - I suspect minimal case is:
(cf (fn [f & args] (apply f args)) (All [b ...] [[b ... b -> Any] b ... b -> Any]))
Hide
Gary Fredericks added a comment -

Indeed I get the same error with that snippet.

Show
Gary Fredericks added a comment - Indeed I get the same error with that snippet.
Hide
Di Xu added a comment -

seems solved this problem

Show
Di Xu added a comment - seems solved this problem
Hide
Ambrose Bonnaire-Sergeant added a comment -

Need to look at this closer, but it seems line 63 completely ignores rest/drest types.

Show
Ambrose Bonnaire-Sergeant added a comment - Need to look at this closer, but it seems line 63 completely ignores rest/drest types.
Hide
Di Xu added a comment -

Oops, that's an error. I added to see how it works, forget to delete it.

The main problem with this patch is it assume user invoke apply with argument that just like declared function type, for example:

(t/ann foo (All [x ...] [Number String x ... x -> bar]))

and invoke with

(apply foo 1 "bar" local-variable)

not

(apply foo 1 local-variable-with-string-in-first)

but I assume this should be the typical usage of apply, no?

Show
Di Xu added a comment - Oops, that's an error. I added to see how it works, forget to delete it. The main problem with this patch is it assume user invoke apply with argument that just like declared function type, for example: (t/ann foo (All [x ...] [Number String x ... x -> bar])) and invoke with (apply foo 1 "bar" local-variable) not (apply foo 1 local-variable-with-string-in-first) but I assume this should be the typical usage of apply, no?
Hide
Ambrose Bonnaire-Sergeant added a comment -

This now has a readable error actually relevant to the problem, as of 0.2.58

Show
Ambrose Bonnaire-Sergeant added a comment - This now has a readable error actually relevant to the problem, as of 0.2.58

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: