jank icon indicating copy to clipboard operation
jank copied to clipboard

Metadata isn't being preserved on conj

Open djblue opened this issue 11 months ago • 1 comments

In jank:

% ./build/jank repl
Bottom of clojure.core
clojure.core=> (meta ^:meta {})
{:meta true}
clojure.core=> (meta (conj ^:meta {} [:k :v]))
nil
clojure.core=> 

In clj:

% clj
Clojure 1.12.0
user=> (meta ^:meta {})
{:meta true}
user=> (meta (conj ^:meta {} [:k :v]))
{:meta true}
user=> 

I haven't investigated further, but this might apply to other operations and collection types.

djblue avatar Jan 18 '25 17:01 djblue

Yep, you're right about this. Meta preservation is likely missing in a lot of places, since metadata was implemented pretty late. We do have all of the behaviors for it now, though. Just need to identify where it's needed.

jeaye avatar Jan 18 '25 20:01 jeaye

@jeaye Should this one be closed?

user=> (meta (conj ^:meta {} [:k :v]))
{:meta true}

And I see Chris already worked on it in one of his previous PR.

shantanu-sardesai avatar Nov 01 '25 05:11 shantanu-sardesai

I suppose this also could do with a few new test cases in the test suite?

shantanu-sardesai avatar Nov 01 '25 05:11 shantanu-sardesai

Yes, we should make sure that meta preservation is tested as well. This is something we're lacking, for coverage.

jeaye avatar Nov 01 '25 18:11 jeaye

It looks like this still requires some work after all:

user=> (let [meta-data {:foo 42} \
user=>...    apply-meta #(-> % (with-meta meta-data) (conj [:k :v]) meta)] \
user=>... (apply-meta '()))
nil

shantanu-sardesai avatar Nov 02 '25 06:11 shantanu-sardesai