ruby-changes:70849
From: Koichi <ko1@a...>
Date: Thu, 13 Jan 2022 17:43:39 +0900 (JST)
Subject: [ruby-changes:70849] 7e21b77dc6 (master): T#dup (T < Proc) should return T's object
https://git.ruby-lang.org/ruby.git/commit/?id=7e21b77dc6 From 7e21b77dc6bfefaf331a0dbf89782303b8cda05d Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Thu, 18 Feb 2021 17:10:39 +0900 Subject: T#dup (T < Proc) should return T's object T#dup (T < Proc) returns Proc object (not T) from Ruby 1.9. [Bug #17545] --- test/ruby/test_proc.rb | 5 +++++ vm.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index 05b2493b247..392b6be665f 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -412,6 +412,11 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L412 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 8ce8b279d43..634ed158847 100644 --- a/vm.c +++ b/vm.c @@ -994,7 +994,7 @@ rb_proc_dup(VALUE self) https://github.com/ruby/ruby/blob/trunk/vm.c#L994 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; -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/