sci icon indicating copy to clipboard operation
sci copied to clipboard

Support setting public static fields in classes

Open lispyclouds opened this issue 3 years ago • 0 comments
trafficstars

Is your feature request related to a problem? Please describe. I stumbled onto this when trying to override the Executor for clojure.lang.Agent. The minimum code that needs to run:

(import '[clojure.lang Agent]
        '[java.util.concurrent Executors])

(set! (.-soloExecutor Agent) (Executors/newFixedThreadPool 10))

Currently, as setting of the public static fields in a class isn't supported, this results in the following error:

----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Invalid assignment target
Data:     {:type :sci/error, :line 4, :column 1, :file "foo.clj", :phase "analysis"}
Location: foo.clj:4:1
Phase:    analysis

----- Context ------------------------------------------------------------------
1: (import '[clojure.lang Agent]
2:         '[java.util.concurrent Executors])
3:
4: (set! (.-soloExecutor Agent) (Executors/newFixedThreadPool 10))
   ^--- Invalid assignment target

----- Stack trace --------------------------------------------------------------
user - foo.clj:4:1

Describe the solution you'd like I should be able to set that field and other public static fields in a class.

Describe alternatives you've considered None

Additional context This is mainly for the ability to be able to override the Executors to support virtual threads in core constructs like (future ...)

lispyclouds avatar Sep 22 '22 12:09 lispyclouds