* proc.c (proc_curry): Fix arity check [Bug #5747]
* test/ruby/test_proc.rb: Test for above git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
83610815d4
commit
f810d1804a
@ -1,3 +1,9 @@
|
|||||||
|
Sat Feb 2 07:45:44 2013 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||||
|
|
||||||
|
* proc.c (proc_curry): Fix arity check [Bug #5747]
|
||||||
|
|
||||||
|
* test/ruby/test_proc.rb: Test for above
|
||||||
|
|
||||||
Sat Feb 2 07:44:15 2013 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
Sat Feb 2 07:44:15 2013 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||||
|
|
||||||
* proc.c: Add {*}_min_max_arity and refactor.
|
* proc.c: Add {*}_min_max_arity and refactor.
|
||||||
|
15
proc.c
15
proc.c
@ -2163,22 +2163,17 @@ curry(VALUE dummy, VALUE args, int argc, VALUE *argv, VALUE passed_proc)
|
|||||||
static VALUE
|
static VALUE
|
||||||
proc_curry(int argc, VALUE *argv, VALUE self)
|
proc_curry(int argc, VALUE *argv, VALUE self)
|
||||||
{
|
{
|
||||||
int sarity, marity = rb_proc_arity(self);
|
int sarity, max_arity, min_arity = rb_proc_min_max_arity(self, &max_arity);
|
||||||
VALUE arity, opt = Qfalse;
|
VALUE arity;
|
||||||
|
|
||||||
if (marity < 0) {
|
|
||||||
marity = -marity - 1;
|
|
||||||
opt = Qtrue;
|
|
||||||
}
|
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "01", &arity);
|
rb_scan_args(argc, argv, "01", &arity);
|
||||||
if (NIL_P(arity)) {
|
if (NIL_P(arity)) {
|
||||||
arity = INT2FIX(marity);
|
arity = INT2FIX(min_arity);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sarity = FIX2INT(arity);
|
sarity = FIX2INT(arity);
|
||||||
if (rb_proc_lambda_p(self) && (sarity < marity || (sarity > marity && !opt))) {
|
if (rb_proc_lambda_p(self)) {
|
||||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", sarity, marity);
|
rb_check_arity(sarity, min_arity, max_arity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +270,13 @@ class TestProc < Test::Unit::TestCase
|
|||||||
assert_equal(self, result[1])
|
assert_equal(self, result[1])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_curry_optional_params
|
||||||
|
obj = Object.new
|
||||||
|
def obj.foo(a, b=42); end
|
||||||
|
assert_raise(ArgumentError) { obj.method(:foo).to_proc.curry(3) }
|
||||||
|
assert_raise(ArgumentError) { ->(a, b=42){}.curry(3) }
|
||||||
|
end
|
||||||
|
|
||||||
def test_dup_clone
|
def test_dup_clone
|
||||||
b = proc {|x| x + "bar" }
|
b = proc {|x| x + "bar" }
|
||||||
class << b; attr_accessor :foo; end
|
class << b; attr_accessor :foo; end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user