Clojure core.typed annotation for apply inside a 3rd-party macro -


i'm using slingshot's throw+ macro raise exception looks like:

(throw+ {:type ::urlparse}) 

the type checker doesn't it:

type error (stream2es/http.clj:79:17) bad arguments apply:  target:     [string t/any * -> string]  arguments:  (persistentlist string) in: (clojure.core/apply clojure.core/format (clojure.core/list "throw+: %s" (clojure.core/pr-str %)))   type checker: found 1 error 

the macro in slingshot looks like:

(defmacro throw+   ([object]      `(throw+ ~object "throw+: %s" (pr-str ~'%)))   ([object message]      `(throw+ ~object "%s" ~message))   ([object fmt arg & args]      `(let [environment# (s/environment)             ~'% ~object             message# (apply format (list ~fmt ~arg ~@args))             stack-trace# (s/stack-trace)]         (s/throw-context ~'% message# stack-trace# environment#)))   ([]      `(s/rethrow))) 

i've tried various ann ^:no-check forms on apply , format , none works. since it's macro, i'm assuming can't annotate since replaces code that's there. can't rewrite code in macro suggested in this other answer, because it's in library. how gradually type in case?

if you’re not able rewrite implementation of throw+, suggest wrapper macro this.

(defmacro typed-throw+ [object]   `(let [o# ~object]      (t/tc-ignore        (throw+ o#))      (throw (exception.)))) ; unreachable ;; other arities exercise .. 

this way, still type check argument, , core.typed still thinks throw+ throws exception — doesn't know that, final throw clause allows core.typed give entire expression type nothing.

the real answer should can improve apply know applying non-empty list satisfy @ least 1 argument, answer should work today.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -