mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* eval.c (rb_yield_0): lambda{}.call(1) should raise exception.
[ruby-talk:120253] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7267 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
eeb6612e72
commit
9d4144af09
3 changed files with 34 additions and 27 deletions
|
@ -1,3 +1,8 @@
|
|||
Mon Nov 15 00:46:03 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* eval.c (rb_yield_0): lambda{}.call(1) should raise exception.
|
||||
[ruby-talk:120253]
|
||||
|
||||
Mon Nov 15 00:33:40 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* string.c (rb_str_clear): avoid revealing NULL pointer.
|
||||
|
|
10
eval.c
10
eval.c
|
@ -4569,6 +4569,9 @@ break_jump(retval)
|
|||
localjump_error("unexpected break", retval, TAG_BREAK);
|
||||
}
|
||||
|
||||
static VALUE bmcall _((VALUE, VALUE));
|
||||
static VALUE method_arity _((VALUE));
|
||||
|
||||
static VALUE
|
||||
rb_yield_0(val, self, klass, flags, avalue)
|
||||
VALUE val, self, klass; /* OK */
|
||||
|
@ -4686,7 +4689,9 @@ rb_yield_0(val, self, klass, flags, avalue)
|
|||
POP_TAG();
|
||||
if (state) goto pop_state;
|
||||
}
|
||||
else if (lambda && RARRAY(val)->len != 0) {
|
||||
else if (lambda && RARRAY(val)->len != 0 &&
|
||||
(!node || nd_type(node) != NODE_IFUNC ||
|
||||
node->nd_cfnc != bmcall)) {
|
||||
rb_raise(rb_eArgError, "wrong number of arguments (%ld for 0)",
|
||||
RARRAY(val)->len);
|
||||
}
|
||||
|
@ -8217,9 +8222,6 @@ proc_call(proc, args)
|
|||
return proc_invoke(proc, args, Qundef, 0);
|
||||
}
|
||||
|
||||
static VALUE bmcall _((VALUE, VALUE));
|
||||
static VALUE method_arity _((VALUE));
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* prc.arity -> fixnum
|
||||
|
|
|
@ -1056,7 +1056,7 @@ test_ok(m1{p 'test'})
|
|||
test_ok(!m1)
|
||||
|
||||
def m
|
||||
m0(block_given?,&proc{})
|
||||
m0(block_given?,&Proc.new{})
|
||||
end
|
||||
test_ok(m1{p 'test'})
|
||||
test_ok(!m1)
|
||||
|
@ -1662,20 +1662,20 @@ test_ok(aaa(1, 2, 3, 4) == [1, 2, 3, 4])
|
|||
test_ok(aaa(1, *[2, 3, 4]) == [1, 2, 3, 4])
|
||||
|
||||
test_check "proc"
|
||||
$proc = proc{|i| i}
|
||||
$proc = Proc.new{|i| i}
|
||||
test_ok($proc.call(2) == 2)
|
||||
test_ok($proc.call(3) == 3)
|
||||
|
||||
$proc = proc{|i| i*2}
|
||||
$proc = Proc.new{|i| i*2}
|
||||
test_ok($proc.call(2) == 4)
|
||||
test_ok($proc.call(3) == 6)
|
||||
|
||||
proc{
|
||||
Proc.new{
|
||||
iii=5 # nested local variable
|
||||
$proc = proc{|i|
|
||||
$proc = Proc.new{|i|
|
||||
iii = i
|
||||
}
|
||||
$proc2 = proc {
|
||||
$proc2 = Proc.new {
|
||||
$x = iii # nested variables shared by procs
|
||||
}
|
||||
# scope of nested variables
|
||||
|
@ -1704,12 +1704,12 @@ if defined? Process.kill
|
|||
test_check "signal"
|
||||
|
||||
$x = 0
|
||||
trap "SIGINT", proc{|sig| $x = 2}
|
||||
trap "SIGINT", Proc.new{|sig| $x = 2}
|
||||
Process.kill "SIGINT", $$
|
||||
sleep 0.1
|
||||
test_ok($x == 2)
|
||||
|
||||
trap "SIGINT", proc{raise "Interrupt"}
|
||||
trap "SIGINT", Proc.new{raise "Interrupt"}
|
||||
|
||||
x = false
|
||||
begin
|
||||
|
@ -1783,51 +1783,51 @@ rescue NameError # must raise error
|
|||
end
|
||||
test_ok(!$bad)
|
||||
|
||||
x = proc{}
|
||||
x = Proc.new{}
|
||||
eval "i4 = 1", x
|
||||
test_ok(eval("i4", x) == 1)
|
||||
x = proc{proc{}}.call
|
||||
x = Proc.new{Proc.new{}}.call
|
||||
eval "i4 = 22", x
|
||||
test_ok(eval("i4", x) == 22)
|
||||
$x = []
|
||||
x = proc{proc{}}.call
|
||||
eval "(0..9).each{|i5| $x[i5] = proc{i5*2}}", x
|
||||
x = Proc.new{Proc.new{}}.call
|
||||
eval "(0..9).each{|i5| $x[i5] = Proc.new{i5*2}}", x
|
||||
test_ok($x[4].call == 8)
|
||||
|
||||
x = binding
|
||||
eval "i = 1", x
|
||||
test_ok(eval("i", x) == 1)
|
||||
x = proc{binding}.call
|
||||
x = Proc.new{binding}.call
|
||||
eval "i = 22", x
|
||||
test_ok(eval("i", x) == 22)
|
||||
$x = []
|
||||
x = proc{binding}.call
|
||||
eval "(0..9).each{|i5| $x[i5] = proc{i5*2}}", x
|
||||
x = Proc.new{binding}.call
|
||||
eval "(0..9).each{|i5| $x[i5] = Proc.new{i5*2}}", x
|
||||
test_ok($x[4].call == 8)
|
||||
x = proc{binding}.call
|
||||
x = Proc.new{binding}.call
|
||||
eval "for i6 in 1..1; j6=i6; end", x
|
||||
test_ok(eval("defined? i6", x))
|
||||
test_ok(eval("defined? j6", x))
|
||||
|
||||
proc {
|
||||
Proc.new {
|
||||
p = binding
|
||||
eval "foo11 = 1", p
|
||||
foo22 = 5
|
||||
proc{foo11=22}.call
|
||||
proc{foo22=55}.call
|
||||
Proc.new{foo11=22}.call
|
||||
Proc.new{foo22=55}.call
|
||||
test_ok(eval("foo11", p) == eval("foo11"))
|
||||
test_ok(eval("foo11") == 1)
|
||||
test_ok(eval("foo22", p) == eval("foo22"))
|
||||
test_ok(eval("foo22") == 55)
|
||||
}.call
|
||||
|
||||
p1 = proc{i7 = 0; proc{i7}}.call
|
||||
p1 = Proc.new{i7 = 0; Proc.new{i7}}.call
|
||||
test_ok(p1.call == 0)
|
||||
eval "i7=5", p1
|
||||
test_ok(p1.call == 5)
|
||||
test_ok(!defined?(i7))
|
||||
|
||||
p1 = proc{i7 = 0; proc{i7}}.call
|
||||
p1 = Proc.new{i7 = 0; Proc.new{i7}}.call
|
||||
i7 = nil
|
||||
test_ok(p1.call == 0)
|
||||
eval "i7=1", p1
|
||||
|
@ -2076,7 +2076,7 @@ test_ok(atlas.ruler4 == "Cronus")
|
|||
test_check "trace"
|
||||
$x = 1234
|
||||
$y = 0
|
||||
trace_var :$x, proc{$y = $x}
|
||||
trace_var :$x, Proc.new{$y = $x}
|
||||
$x = 40414
|
||||
test_ok($y == $x)
|
||||
|
||||
|
@ -2084,7 +2084,7 @@ untrace_var :$x
|
|||
$x = 19660208
|
||||
test_ok($y != $x)
|
||||
|
||||
trace_var :$x, proc{$x *= 2}
|
||||
trace_var :$x, Proc.new{$x *= 2}
|
||||
$x = 5
|
||||
test_ok($x == 10)
|
||||
|
||||
|
|
Loading…
Reference in a new issue