Project

General

Profile

Actions

Bug #2679

closed

rubyspec: SimpleDelegator when frozen creates a frozen clone ERROR

Added by mame (Yusuke Endoh) almost 15 years ago. Updated over 13 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.2dev (2010-01-29 trunk 26468) [i686-linux]
Backport:
[ruby-dev:40221]

Description

=begin
まつもとさん、または lib/delegator.rb についてわかる誰か
遠藤です。

freeze した SimpleDelegator を clone できません。

$ ./ruby -rdelegate -e '
a = [42, :hello]
d = SimpleDelegator.new(a)
d.freeze
d.clone
'
/home/mame/work/ruby-trunk-local/lib/ruby/1.9.1/delegate.rb:257:in
__setobj__': can't modify frozen object (RuntimeError) from /home/mame/work/ruby-trunk-local/lib/ruby/1.9.1/delegate.rb:207:in clone'
from -e:5:in `'

これはバグですよね。

lib/delegator.rb の clone の定義を見ると

def clone
new = super
new.setobj(getobj.clone)
new
end

となっていて、setobj するときにはもう SimpleDelegetor は freeze
状態なのでそりゃそうだという感じなんですが、どう直したものでしょう。

--
Yusuke ENDOH
=end


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Bug #2221: lib/delegate: freeze has odd effectsClosed10/16/2009Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0