Clojure

array-map fails lazily if passed an odd number of arguments

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test

Description

If called with an odd number of arguments, array-map does not throw an exception until the map is realized, when it throws the confusing ArrayIndexOutOfBoundsException.

Example, in 1.5.1 and 1.6.0-alpha3:

user=> (def m (array-map :a 1 :b))
#'user/m

user=> (prn m)
ArrayIndexOutOfBoundsException 3
  clojure.lang.PersistentArrayMap$Seq.first
  (PersistentArrayMap.java:313)

Activity

Hide
Jason Felice added a comment -

A better error message would be nice... this is the best I could think of.

Show
Jason Felice added a comment - A better error message would be nice... this is the best I could think of.
Hide
Alex Miller added a comment -

PersistentArrayMap.createAsIfByAssoc could check length is even to catch this

Show
Alex Miller added a comment - PersistentArrayMap.createAsIfByAssoc could check length is even to catch this

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: