diff options
author | PikachuEXE <pikachuexe@gmail.com> | 2021-08-05 15:51:15 +0800 |
---|---|---|
committer | usa <usa@garbagecollect.jp> | 2021-11-24 16:47:15 +0900 |
commit | eeabac4c55e0968e3664728bcce3c0eb23cd9321 (patch) | |
tree | c0ba580e13a87fef23c69f51185864f095549446 /test/ruby | |
parent | e0b323632f5ea07e2646a2ec0b72f56093348265 (diff) |
Do not allow Module#include to insert modules before the origin in the lookup chain
Module#include should only be able to insert modules after the origin,
otherwise it ends up working like Module#prepend.
This fixes the case where one of the modules in the included module
chain is included in a module that is already prepended to the receiver.
Fixes [Bug #7844]
Backport of https://github.com/ruby/ruby/pull/3796 to 2.7
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_module.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 5cfda018f3..231ccd2072 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -472,6 +472,16 @@ class TestModule < Test::Unit::TestCase assert_equal([Comparable, Kernel], String.included_modules - mixins) end + def test_include_with_prepend + c = Class.new{def m; [:c] end} + p = Module.new{def m; [:p] + super end} + q = Module.new{def m; [:q] + super end; include p} + r = Module.new{def m; [:r] + super end; prepend q} + s = Module.new{def m; [:s] + super end; include r} + a = Class.new(c){def m; [:a] + super end; prepend p; include s} + assert_equal([:p, :a, :s, :q, :r, :c], a.new.m) + end + def test_instance_methods assert_equal([:user, :user2], User.instance_methods(false).sort) assert_equal([:user, :user2, :mixin].sort, User.instance_methods(true).sort) |