summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2021-02-18 17:10:39 +0900
committerKoichi Sasada <ko1@atdot.net>2022-01-13 17:43:14 +0900
commit7e21b77dc6bfefaf331a0dbf89782303b8cda05d (patch)
tree53de2f22527722e03837f2528448293dfe840e7a
parent5a75151a0166ded78fc87ef5891a6877ba0950db (diff)
T#dup (T < Proc) should return T's object
T#dup (T < Proc) returns Proc object (not T) from Ruby 1.9. [Bug #17545]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4197
-rw-r--r--test/ruby/test_proc.rb5
-rw-r--r--vm.c2
2 files changed, 6 insertions, 1 deletions
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index 05b2493b24..392b6be665 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -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
diff --git a/vm.c b/vm.c
index 8ce8b279d4..634ed15884 100644
--- a/vm.c
+++ b/vm.c
@@ -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;