Uploaded image for project: 'ClojureScript'
  1. CLJS-2149

aget produces different results from Clojure for non-integer and out-of-bounds indexes

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects versions: 1.9.671
    • Fix versions: None
    • Labels:
      None

      Description

      Like CLJS-2113 Closed , but for aget:

      Clojure:

      user=> (aget (to-array [nil 1]) -1)
      ArrayIndexOutOfBoundsException -1  clojure.lang.RT.aget (RT.java:2336)
      user=> (aget (to-array [nil 1]) 0)
      nil
      user=> (aget (to-array [nil 1]) 0.5)
      nil
      user=> (aget (to-array [nil 1]) 1)
      1
      user=> (aget (to-array [nil 1]) 1.5)
      1
      user=> (aget (to-array [nil 1]) 2)
      ArrayIndexOutOfBoundsException 2  clojure.lang.RT.aget (RT.java:2336)
      

      ClojureScript

      cljs.user=> (aget (to-array [nil 1]) -1)
      nil
      cljs.user=> (aget (to-array [nil 1]) 0)
      nil
      cljs.user=> (aget (to-array [nil 1]) 0.5)
      nil
      cljs.user=> (aget (to-array [nil 1]) 1)
      1
      cljs.user=> (aget (to-array [nil 1]) 1.5)
      nil
      cljs.user=> (aget (to-array [nil 1]) 2)
      nil
      

      Also note that Clojure acts as if rounding indices down to the nearest integer while ClojureScript does not:

      (aget (to-array [1 2]) 0.5) 
      

      yields 1 in Clojure and nil in ClojureScript.

      (Presumably, similar results hold for aset.)

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              mfikes Mike Fikes
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: