Uploaded image for project: 'Clojure'
  1. CLJ-1093

Empty PersistentCollections get incorrectly evaluated as their generic clojure counterpart

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Completed
    • Affects versions: Release 1.5, Release 1.4
    • Fix versions: Release 1.8
    • Patch:
      Code and Test

      Description

      user> (defrecord x [])
      user.x
      user> #user.x[]   ;; expect: #user.x{}
      {}
      user> #user.x{}   ;; expect: #user.x{}
      {}
      user> #clojure.lang.PersistentTreeMap[]
      {}
      user> (class *1)  ;; expect: clojure.lang.PersistentTreeMap
      clojure.lang.PersistentArrayMap
      

      Cause: Compiler's ConstantExpr parser returns an EmptyExpr for all empty persistent collections, even if they are of types other than the core collections (for example: records, sorted collections, custom collections). EmptyExpr reports its java class as one the classes - IPersistentList/IPersistentVector/IPersistentMap/IPersistentSet rather than the original type.

      Proposed: If one of the Persistent* classes, then create EmptyExpr as before, otherwise retain the ConstantExpression of the original collection.
      Since EmptyExpr is a compiler optimization that applies only to some concrete clojure collections, making EmptyExpr dispatch on concrete types rather than on generic interfaces makes the compiler behave as expected

      Patch: 0001-CLJ-1093-v2.patch

      Screened by:

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              bronsa Nicola Mometto
            • Votes:
              3 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: