1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

T#dup (T < Proc) should return T's object

T#dup (T < Proc) returns Proc object (not T) from Ruby 1.9.
[Bug #17545]
This commit is contained in:
Koichi Sasada 2021-02-18 17:10:39 +09:00
parent 5a75151a01
commit 7e21b77dc6
Notes: git 2022-01-13 17:43:42 +09:00
2 changed files with 6 additions and 1 deletions

View file

@ -412,6 +412,11 @@ class TestProc < Test::Unit::TestCase
assert_equal(:foo, bc.foo)
end
def test_dup_subclass
c1 = Class.new(Proc)
assert_equal c1, c1.new{}.dup.class, '[Bug #17545]'
end
def test_binding
b = proc {|x, y, z| proc {}.binding }.call(1, 2, 3)
class << b; attr_accessor :foo; end

2
vm.c
View file

@ -994,7 +994,7 @@ rb_proc_dup(VALUE self)
rb_proc_t *src;
GetProcPtr(self, src);
procval = proc_create(rb_cProc, &src->block, src->is_from_method, src->is_lambda);
procval = proc_create(rb_obj_class(self), &src->block, src->is_from_method, src->is_lambda);
if (RB_OBJ_SHAREABLE_P(self)) FL_SET_RAW(procval, RUBY_FL_SHAREABLE);
RB_GC_GUARD(self); /* for: body = rb_proc_dup(body) */
return procval;