Issue #5747 has been reported by Marc-Andre Lafortune.

----------------------------------------
Bug #5747: Proc#curry doesn't always detect too many arguments 
http://redmine.ruby-lang.org/issues/5747

Author: Marc-Andre Lafortune
Status: Open
Priority: Normal
Assignee: Marc-Andre Lafortune
Category: core
Target version: 
ruby -v: -


Currently, Proc#curry checks the validity of the `arity` argument and will raise an error if:

1) arity is less than the number of required arguments or
2) arity is more than the maximum number of arguments
Note that simple Procs always accept any number of arguments (even though they may be ignored), so (2) doesn't applies to them, only to lambda's and procs made from methods. 

#2 isn't done as well as it could in case of limited optional parameters:

    def Object.foo(a, b=42); end
    def Object.bar(a, b);    end

    Object.method(:foo).to_proc.curry(3) # => curried proc which will raise an error only when passed it's 3rd parameter
    Object.method(:bar).to_proc.curry(3) # => ArgumentError: wrong number of arguments (3 for 2)
    
    Same thing with lambdas

My proposed fix passes SST:
a) usefulness: "fail-early" principle [ruby-core:24130]
b) consistency: both methods can only accept a maximum of 2 parameters and are thus treated consistently when attempting to curry with more than 2 arguments
c) intuitiveness and d) performance: similar

It is straightforward (but not obvious), as it passes NIT (but not ODT).



-- 
http://redmine.ruby-lang.org