ClojureScript

Variable argument functions break when first vararg is undefined

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

If the first of the variable arguments to a vararg function is the javascript value undefined, the function behaves as though it didn't receive any variable arguments at all:

(defn f [& rest] rest)

(f 1 2 3)
;; => (1 2 3) ; correct

(f 1 js/undefined 3)
;; => (1 nil 3) ; correct

(f js/undefined 2 3)
;; => nil ; wrong

Activity

Hide
Matjaz Gregoric added a comment -

Attaching a patch that determines whether varargs were passed to the function by examining arguments.length rather than checking the first argument in the vararg position with goog.isDef(arg).

Show
Matjaz Gregoric added a comment - Attaching a patch that determines whether varargs were passed to the function by examining arguments.length rather than checking the first argument in the vararg position with goog.isDef(arg).
Hide
David Nolen added a comment -

This looks good, thanks!

Show
David Nolen added a comment - This looks good, thanks!

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: