[ruby-core:102292] [Ruby master Bug#17545] Calling dup on a subclass of Proc returns a Proc and not the subclass
From:
ko1@...
Date:
2021-01-29 09:03:59 UTC
List:
ruby-core #102292
Issue #17545 has been updated by ko1 (Koichi Sasada).
Assignee set to ko1 (Koichi Sasada)
Status changed from Open to Assigned
This behavior is from ruby 1.9.
Matz, is it a bug?
```
@all-ruby -e 'class Test < Proc; end; p Test.new { puts "foo" }.dup.class'
:ok: 1.8
Test
:ok: 1.9 -- 98e27016c9 (2021-01-29T07:22:12Z)
Proc
```
----------------------------------------
Bug #17545: Calling dup on a subclass of Proc returns a Proc and not the subclass
https://bugs.ruby-lang.org/issues/17545#change-90147
* Author: lamont (Lamont Granquist)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* ruby -v: ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
Trivial example:
``` ruby
[1] pry(main)> class Test < Proc; end
=> nil
[3] pry(main)> Test.new { puts "foo" }.dup
=> #<Proc:0x00007f91a78913c8 (pry):3>
```
Also fairly trivial workaround:
```ruby
[4] pry(main)> class Test < Proc
[4] pry(main)* def dup
[4] pry(main)* self.class.new(&super)
[4] pry(main)* end
[4] pry(main)* end
=> :dup
[5] pry(main)> Test.new { puts "foo" }.dup
=> #<Test:0x00007f91b8e73e38 (pry):9>
```
Seems like a bug though, Proc#dup is probably calling the ruby-c equivalent of Proc.new rather than self.class.new and bypassing subclassing
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>