Clojure

Clojure loses quoted metadata on empty literals

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Duplicate
  • Affects Version/s: Release 1.5, Release 1.6
  • Fix Version/s: Release 1.7
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test
  • Approval:
    Vetted

Description

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: 001-CLJ-1187.patch (NOTE: this change overlaps with CLJ-1093 and the patch there may be preferred)

Screened by:

Activity

Hide
Nicola Mometto added a comment -

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}

Show
Nicola Mometto added a comment - 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}
Hide
Stuart Halloway added a comment -

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

Show
Stuart Halloway added a comment - I believe the title should read "Clojure loses quoted metdata on empty literals".
Hide
Stuart Halloway added a comment -

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.

Show
Stuart Halloway added a comment - 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.
Hide
Nicola Mometto added a comment -

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

Show
Nicola Mometto added a comment - You're right, I've updated my patch, it should work as expected now
Hide
Andy Fingerhut added a comment -

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

Show
Andy Fingerhut added a comment - Nicola: Your updated patch 001-CLJ-1187.patch dated Mar 29, 2013 gives syntax errors when I try to compile it.
Hide
Nicola Mometto added a comment -

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

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

Show
Nicola Mometto added a comment - Oh, the irony, I messed up some parentheses writing java. Sorry for it, here's the correct patch, it applies on upstream/master.
Hide
Gabriel Horner added a comment -

Looks good

Show
Gabriel Horner added a comment - Looks good
Hide
Nicola Mometto added a comment -

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

Show
Nicola Mometto added a comment - CLJ-1093 contains a patch that fixes this issue aswell and should be preferred
Hide
Alex Miller added a comment -

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

Show
Alex Miller added a comment - Marking un-Screened due to the note about CLJ-1093. Want to assess this more before going through Rich.
Hide
Alex Miller added a comment -

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

Show
Alex Miller added a comment - Switching to Incomplete pending CLJ-1093 which I hope to pull into 1.6.
Hide
Alex Miller added a comment -

Pulling out of 1.6, will consider in next release.

Show
Alex Miller added a comment - Pulling out of 1.6, will consider in next release.
Hide
Alex Miller added a comment -

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

Show
Alex Miller added a comment - Dupe of CLJ-1093, closed at Nicola's request.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: