Make a cyclic prepend not modify ancestors for the receiver

Check for cyclic prepend before making any changes.  This requires
scanning the module ancestor chain twice, but in general modules
do not have large numbers of ancestors.
This commit is contained in:
Jeremy Evans 2021-02-09 15:39:34 -08:00
parent b83ad02997
commit 2d877327e1
Notes: git 2021-02-12 00:46:21 +09:00
2 changed files with 19 additions and 2 deletions

View file

@ -478,6 +478,13 @@ class TestModule < Test::Unit::TestCase
assert_raise(ArgumentError) { Module.new { include } }
end
def test_prepend_self
m = Module.new
assert_equal([m], m.ancestors)
m.prepend(m) rescue nil
assert_equal([m], m.ancestors)
end
def test_prepend_works_with_duped_classes
m = Module.new
a = Class.new do