ClojureScript

variadic defn can be called for missing fixed arities, overlapping arity

Details

  • Type: Defect Defect
  • Status: Reopened Reopened
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.9.671
  • Fix Version/s: Next
  • Component/s: None
  • Labels:

Description

For defns with a variadic arity: if invoked with a missing fixed arity, they use the variadic method instead of erroring; if invoked with a fixed arity that is the max fixed arity, variadic mathod instead of fixed form is invoked.

(defn f-hole
  ([a] 1)
  ([a b c d & args] "4 or more"))

(f-hole 1 2) ; =>"4 or more", should be error

(defn f-overlap-mfa
  ([a b] 2)
  ([a b & c] "2+"))

(f-overlap-mfa 1) ;=> "2+", should be error
(f-overlap-mfa 1 2) ;=> "2+", should be 2
(f-overlap-mfa 1 2 3) ;=> "2+", correct

A way to fix the f-hole bug is to emit a "case X:" into the switch statement for all X with no signature or less than max-fixed-arity.

The f-overlap-mfa I'm not sure why is happening and didn't investigate deeply.

Activity

Hide
Francis Avila added a comment -

Sorry, filed against CLJ instead of CLJS!

Show
Francis Avila added a comment - Sorry, filed against CLJ instead of CLJS!
Hide
Rohit Aggarwal added a comment -

The behaviour I am seeing for f-overlap-mfa is:

(f-overlap-mfa 1) ;=> "2+"
(f-overlap-mfa 1 2) ;=> 2
(f-overlap-mfa 1 2 3) ;=> "2+"

So the two argument result is different for me than you, Francis Avila.

The call with just one argument does give a warning though:

WARNING: Wrong number of args (1) passed to cljs.user/f-overlap-mfa

Show
Rohit Aggarwal added a comment - The behaviour I am seeing for f-overlap-mfa is:
(f-overlap-mfa 1) ;=> "2+"
(f-overlap-mfa 1 2) ;=> 2
(f-overlap-mfa 1 2 3) ;=> "2+"
So the two argument result is different for me than you, Francis Avila. The call with just one argument does give a warning though: WARNING: Wrong number of args (1) passed to cljs.user/f-overlap-mfa

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: