Support setting public static fields in classes

Open
#804 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
clojure, java
Domain
tooling

Research direction

Reproduce the failure with set! on clojure.lang.Agent.soloExecutor using the example and inspect the analyzer path that reports Invalid assignment target. Trace how field access and assignment are handled, then verify that public static fields such as soloExecutor can be assigned while existing assignment behavior remains unchanged.

Written by the indexing model from the issue text.

Description

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 ...)

Dominant language
Clojure
Stars
1.4k
Forks
109
Avg merge
1m
Merged PRs (30d)
26

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from babashka/sci

All issues in babashka/sci

Similar issues

More Clojure issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.