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

Nicola Mometto made changes -
Field Original Value New Value
Attachment 001-CLJ-1187.patch [ 11926 ]
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}
Nicola Mometto made changes -
Patch Code and Test [ 10002 ]
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".
Stuart Halloway made changes -
Approval Triaged [ 10120 ]
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.
Nicola Mometto made changes -
Attachment 001-CLJ-1187.patch [ 11926 ]
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
Nicola Mometto made changes -
Attachment 001-CLJ-1187.patch [ 11931 ]
Nicola Mometto made changes -
Summary Quoted empty literals lose metadata Clojure loses quoted metdata on empty literals
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.
Nicola Mometto made changes -
Attachment 001-CLJ-1187.patch [ 11931 ]
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.
Nicola Mometto made changes -
Attachment 001-CLJ-1187.patch [ 11943 ]
Rich Hickey made changes -
Approval Triaged [ 10120 ] Vetted [ 10003 ]
Rich Hickey made changes -
Fix Version/s Release 1.6 [ 10157 ]
Gabriel Horner made changes -
Assignee Gabriel Horner [ cldwalker ]
Hide
Gabriel Horner added a comment -

Looks good

Show
Gabriel Horner added a comment - Looks good
Gabriel Horner made changes -
Approval Vetted [ 10003 ] Screened [ 10004 ]
Assignee Gabriel Horner [ cldwalker ]
Summary Clojure loses quoted metdata on empty literals Clojure loses quoted metadata on empty literals
Nicola Mometto made changes -
Description user=> (meta '^:foo [])
nil

while
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}
##NOTE##
CLJ-1093 contains a patch that fixes this issue aswell and should be preferred



user=> (meta '^:foo [])
nil

while
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}
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.
Alex Miller made changes -
Approval Screened [ 10004 ] Vetted [ 10003 ]
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.
Alex Miller made changes -
Approval Vetted [ 10003 ] Incomplete [ 10006 ]
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.
Alex Miller made changes -
Fix Version/s Release 1.6 [ 10157 ]
Alex Miller made changes -
Approval Incomplete [ 10006 ] Vetted [ 10003 ]
Alex Miller made changes -
Description ##NOTE##
CLJ-1093 contains a patch that fixes this issue aswell and should be preferred



user=> (meta '^:foo [])
nil

while
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}
meta on empty collections is lost:

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

This bug propagates to ^:const vars:
{code}
user=> (def ^:const foo ^:foo [])
#'user/foo
user=> (meta foo)
nil
user=> (meta @#'foo)
{:foo true}
{code}

*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:*
Rich Hickey made changes -
Fix Version/s Release 1.7 [ 10250 ]
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.
Alex Miller made changes -
Resolution Duplicate [ 3 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: