Welcome! Please see the About page for a little more info on how this works.

0 votes
in Collections by
meta on empty collections is lost:


user=> (meta '^:foo [])
nil   ;; expected {:foo true} as in:
user=> (meta '^:foo [1])
{:foo true}


This bug propagates to ^:const vars:

user=> (def ^:const foo ^:foo [])
#'user/foo
user=> (meta foo)
nil
user=> (meta @#'foo)
{:foo true}


*Cause:* As in CLJ-1093, empty collections are replaced with an EmptyExpr that loses meta

*Proposed:* Don't replace with EmptyExpr if meta is present.

*Patch:* 0001-Support-retrieval-of-metadata-from-quoted-empty-lite.patch

*Screened by:*

18 Answers

0 votes
by
_Comment made by: bronsa_

After patch:

user=> (meta '^:foo [])
{:foo true}
user=> (meta '^:foo [:a])
{:foo true}
user=> (def ^:const foo ^:foo [])
#'user/foo
user=> (meta foo)
{:foo true}

0 votes
by

Comment made by: stu

I believe the title should read "Clojure loses quoted metdata on empty literals".

0 votes
by

Comment made by: stu

At first glance, the implementation looks wrong in that it blocks non-IObjs ever getting to EmptyExpr. Probably all persistent collections are IObjs, but would not want to bake this in.

0 votes
by

Comment made by: bronsa

You're right, I've updated my patch, it should work as expected now

0 votes
by

Comment made by: jafingerhut

Nicola: Your updated patch 001-CLJ-1187.patch dated Mar 29, 2013 gives syntax errors when I try to compile it.

0 votes
by

Comment made by: bronsa

Oh, the irony, I messed up some parentheses writing java.

Sorry for it, here's the correct patch, it applies on upstream/master.

0 votes
by

Comment made by: cldwalker

Looks good

0 votes
by

Comment made by: bronsa

CLJ-1093 contains a patch that fixes this issue aswell and should be preferred

0 votes
by

Comment made by: alexmiller

Marking un-Screened due to the note about CLJ-1093. Want to assess this more before going through Rich.

0 votes
by

Comment made by: alexmiller

Switching to Incomplete pending CLJ-1093 which I hope to pull into 1.6.

0 votes
by

Comment made by: alexmiller

Pulling out of 1.6, will consider in next release.

0 votes
by

Comment made by: alexmiller

Dupe of CLJ-1093, closed at Nicola's request.

0 votes
by

Comment made by: bronsa

Reopening this since the fix that got applied for CLJ-1093 didn't subsume this one

0 votes
by

Comment made by: bronsa

Refreshed and squashed patch

0 votes
by

Comment made by: sohta

Any chance this will be fixed yet? I've run into it recently.

...