Project

General

Profile

Bug #8297 ยป singleton-class-class-variable-lookup-8297.patch

jeremyevans0 (Jeremy Evans), 08/10/2019 04:29 AM

View differences:

test/ruby/test_variable.rb
35 35
    end
36 36
  end
37 37

  
38
  def test_singleton_class_included_class_variable
39
    c = Class.new
40
    c.extend(Olympians)
41
    assert_empty(c.singleton_class.class_variables)
42
    assert_raise(NameError){ c.singleton_class.class_variable_get(:@@rule) }
43
    c.class_variable_set(:@@foo, 1)
44
    assert_equal([:@@foo], c.singleton_class.class_variables)
45
    assert_equal(1, c.singleton_class.class_variable_get(:@@foo))
46
    
47
    c = Class.new
48
    c.extend(Olympians)
49
    sc = Class.new(c)
50
    assert_empty(sc.singleton_class.class_variables)
51
    assert_raise(NameError){ sc.singleton_class.class_variable_get(:@@rule) }
52
    c.class_variable_set(:@@foo, 1)
53
    assert_equal([:@@foo], sc.singleton_class.class_variables)
54
    assert_equal(1, sc.singleton_class.class_variable_get(:@@foo))
55

  
56
    c = Class.new
57
    o = c.new
58
    o.extend(Olympians)
59
    assert_equal([:@@rule], o.singleton_class.class_variables)
60
    assert_equal("Zeus", o.singleton_class.class_variable_get(:@@rule))
61
    c.class_variable_set(:@@foo, 1)
62
    assert_equal([:@@foo, :@@rule], o.singleton_class.class_variables.sort)
63
    assert_equal(1, o.singleton_class.class_variable_get(:@@foo))
64
  end
65

  
38 66
  def test_variable
39 67
    assert_instance_of(Integer, $$)
40 68

  
variable.c
3266 3266
mod_cvar_of(VALUE mod, void *data)
3267 3267
{
3268 3268
    VALUE tmp = mod;
3269
    if (FL_TEST(mod, FL_SINGLETON)) {
3270
        if (rb_namespace_p(rb_ivar_get(mod, id__attached__))) {
3271
            data = mod_cvar_at(tmp, data);
3272
            tmp = cvar_front_klass(tmp);
3273
        }
3274
    }
3269 3275
    for (;;) {
3270 3276
	data = mod_cvar_at(tmp, data);
3271 3277
	tmp = RCLASS_SUPER(tmp);
3272
-