Project

General

Profile

Actions

Bug #9813

closed

Module#initialize_copy does not clean the tables

Added by nobu (Nobuyoshi Nakada) almost 10 years ago. Updated almost 10 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
r45873
[ruby-dev:48182]

Description

Module#initialize_copyで定数やインスタンス変数を持たないModuleをコピーしても、元の定数やインスタンス変数が残っています。

m = Module.new do
  def x
  end
  const_set(:X, 1)
  @x = 2
end
p m.instance_methods, m.instance_variables, m.constants
#=> [:x]
#=> [:@x]
#=> [:X]
m.module_eval do
  initialize_copy(Module.new)
end
p m.instance_methods, m.instance_variables, m.constants
#=> []
#=> [:@x]
#=> [:X]

1.8でinitialize_copyが導入された当初からあるバグのようです。

Updated by nobu (Nobuyoshi Nakada) almost 10 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Applied in changeset r45874.


class.c: always clear tables first

  • class.c (rb_mod_init_copy): always clear instance variable,
    constant and method tables first, regardless the source tables.
    [ruby-dev:48182] [Bug #9813]

Updated by nagachika (Tomoyuki Chikanaga) almost 10 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED to 2.0.0: REQUIRED, 2.1: DONE

Backported into ruby_2_1 branch at r46498.

Updated by usa (Usaku NAKAMURA) almost 10 years ago

backported into ruby_2_0_0 at r46519.

Updated by usa (Usaku NAKAMURA) almost 10 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: DONE to 2.0.0: DONE, 2.1: DONE
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0