Project

General

Profile

Actions

Bug #9603

closed

unusual reference class-variable with cloned class.

Added by Chiether (Norikaz Ishii) about 10 years ago. Updated over 4 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.2p80 (2014-03-01 revision 45231) [x86_64-linux]
Backport:
[ruby-core:61336]

Description

description

Maybe panic reference to class-variable in cloned class. Not really sure about bug. But hang over my head.
I think minor irritant it which whether problem or not. because impractical code.

sample code

class A
  @@value = 1
  def self.make_instance
    @@value = 2
    new
  end
  def data
    @@value
  end
end
puts A.make_instance.data # => 2 -- collect!!

class B
  def self.make_clone
    C.clone
  end
  class C
    @@value = 1
    def self.make_instance
      @@value = 2
      new
    end
    def data
      @@value
    end
  end
end
[pattern 1]
puts B.make_clone.make_instance.data  # => 1 -- wrong
puts B.make_clone.make_instance.data  # => 2 -- collect
[pattern 2]
puts B::C.make_instance.data          # => 2 -- collect
puts B.make_clone.make_instance.data  # => 2 -- collect

expected

[pattern 1]
2
2
[pattern 2]
2
2

actual

[pattern 1]
1
2
[pattern 2]
2
2

noticed

ruby-1.8.6-p420, ruby-1.9.3-p545, ruby 2.1.2p80 all problem.
but codepad(1.8.6) is looking for expected. http://codepad.org/1VPpyCvy

Actions

Also available in: Atom PDF

Like0
Like0Like0