diff --git a/ChangeLog b/ChangeLog index b88dc87aee..ed7c82149d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Aug 1 00:33:19 2012 Nobuyoshi Nakada + + * class.c (include_class_new): fix duplication of prepended module. + since m_tbl of prepended module is always zero, copy from its + copy iclass of original. + Tue Jul 31 18:22:34 2012 Nobuyoshi Nakada * variable.c (classname): tell if found name is permanent. search diff --git a/class.c b/class.c index d81c093c9c..1253ce80b7 100644 --- a/class.c +++ b/class.c @@ -636,7 +636,7 @@ include_class_new(VALUE module, VALUE super) } RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module); RCLASS_CONST_TBL(klass) = RCLASS_CONST_TBL(module); - RCLASS_M_TBL(klass) = RCLASS_M_TBL(module); + RCLASS_M_TBL(klass) = RCLASS_M_TBL(RCLASS_ORIGIN(module)); RCLASS_SUPER(klass) = super; if (RB_TYPE_P(module, T_ICLASS)) { RBASIC(klass)->klass = RBASIC(module)->klass; diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 43e80a5955..4e5f8856a6 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1356,6 +1356,15 @@ class TestModule < Test::Unit::TestCase assert_equal([:m0, :m1, :m2, :c1], c1.new.x) assert_equal([c2, m0, m1, m2, c0], c2.ancestors[0, 5], bug6662) assert_equal([:c2, :m0, :m1, :m2, :c0], c2.new.x) + + m3 = labeled_module("m3") {include m1; prepend m1} + assert_equal([m3, m0, m1], m3.ancestors) + m3 = labeled_module("m3") {prepend m1; include m1} + assert_equal([m0, m1, m3], m3.ancestors) + m3 = labeled_module("m3") {prepend m1; prepend m1} + assert_equal([m0, m1, m3], m3.ancestors) + m3 = labeled_module("m3") {include m1; include m1} + assert_equal([m3, m0, m1], m3.ancestors) end def labeled_module(name, &block)