clr

2024-12-23T15:30:13.814669Z

I have a question on generics. I need to interface with Tasks. So I want to make a task from a result. When I try: `(System.Threading.Tasks.Task/Run (sys-func [System.Object] [] nil))` It works, but when I try: (^|System.Threading.Tasks.Task1[System.Object]| System.Threading.Tasks.Task/FromResult nil))` I get an error on compilation (loading a program with incorrect format). Ive tried to put the type hint on several places. But simply cannot get it to work. (It compiles when ai move the type hint before the open paren, but then it fails on execution). Is this supported? and how?

2024-12-24T08:52:48.560459Z

Yes:

(^|System.Threading.Tasks.Task`1[System.Object]|
   System.Threading.Tasks.Task/FromResult
     (type-args System.Object)
   nil))

👍 1
2024-12-24T08:57:38.430619Z

Without the first meta tag, it also compiles fine:

(System.Threading.Tasks.Task/FromResult
   (type-args System.Object)
   nil))

dmiller 2024-12-24T14:46:52.169119Z

The "loading a program with incorrect format" is not very helpful. The compiler should catch bad IL generation before that. I'll see what I can do.

dmiller 2024-12-24T15:17:51.608069Z

BTW, if you supply type-args and they are not needed or have the wrong count, one gets more informative error messages: The type or method has 1 generic parameter(s), but 2 generic argument(s) were provided. A generic argument must be provided for each generic parameter. Wrong number of args (2) passed to: clojure.core/type-args--7168 (Maybe the latter could be improved.) Issue created: [CLJCLR-165](https://clojure.atlassian.net/jira/software/c/projects/CLJCLR/issues/CLJCLR-165).

dmiller 2024-12-24T16:31:31.274509Z

The fix will be in the next release.

2024-12-23T15:33:06.467219Z

Found it, use type-args

dmiller 2024-12-24T02:27:10.588139Z

Post the working code for reference?