Issue #9573 has been updated by jeremyevans0 (Jeremy Evans).

File prepend-future-ancestors-9573.patch added

Attached is a work-in-progress patch that includes similar support for `Module#prepend`.  It does work in terms of `Module#prepend` affecting classes/modules that have already included the receiver, but it causes failures in the tests that would need to be fixed.  Example:

```ruby
class Object def foo; [] end end
module A def foo; [:A] + super end end
module B def foo; [:B] + super end end
module C def foo; [:C] + super end end
module D def foo; [:D] + super end end
module E
  include C
  prepend D
  def foo; [:E] + super end
end

module Enumerable def foo; [:Enumerable] + super end
end

Enumerable.include A
Enumerable.prepend B
Enumerable.include E

p [].foo
p({}.foo)
```

Output:

```
[:B, :Enumerable, :D, :E, :C, :A]
[:B, :Enumerable, :D, :E, :C, :A]
```

This does require creating origin iclasses for all modules that are included or prepended to other modules.  It changes the origin pointer handling for iclasses such that the iclass origin pointer points not to the module origin but to the iclass origin.  Due to the way module inclusion works, the iclass origin is not created at the point the iclass is created, so we need to keep a record of the created iclass, and when we come across the module origin and create the iclass origin, we set the origin for the iclass to the iclass origin.

Before doing more work in this area to attempt to fix the test failures, we should decide if we want this behavior and whether the necessary tradeoff of doubling the number of iclasses is worth it.  Here are a few of the 43 test-all failures:

```
  1) Failure:
Complex_Test#test_respond [/home/jeremy/tmp/ruby/test/ruby/test_complex.rb:934]:
Complex#clamp.
Expected (1+1i) to not respond to clamp.

  2) Failure:
TestModule#test_override_optmethod_after_prepend [/home/jeremy/tmp/ruby/test/ruby/test_module.rb:1990]:
[ruby-core:72226] [Bug #11836].
<(1/2)> expected but was
<0>.

...

 42) Error:
TestAlias#test_super_in_aliased_module_method:
NoMethodError: super: no superclass method `foo' for #<TestAlias::SuperInAliasedModuleMethod::Derived:0x000006e8b02d3d78>
Did you mean?  for
    /home/jeremy/tmp/ruby/test/ruby/test_alias.rb:96:in `foo'
    /home/jeremy/tmp/ruby/test/ruby/test_alias.rb:115:in `test_super_in_aliased_module_method'

 43) Error:
TestRefinement#test_refine_module:
NoMethodError: super: no superclass method `bar' for #<TestRefinement::RefineModule::C:0x000006e8afad0018>
Did you mean?  baz
    /home/jeremy/tmp/ruby/test/ruby/test_refinement.rb:453:in `bar'
    /home/jeremy/tmp/ruby/test/ruby/test_refinement.rb:469:in `call_bar'
    /home/jeremy/tmp/ruby/test/ruby/test_refinement.rb:479:in `test_refine_module'
```

----------------------------------------
Bug #9573: descendants of a module don't gain its future ancestors, but descendants of a class, do
https://bugs.ruby-lang.org/issues/9573#change-83706

* Author: rits (First Last)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.1.1p76 (2014-02-24 revision 45161) [i686-linux]
* Backport: 
----------------------------------------
```ruby
module Mod1
end

module Mod2
end

class Class1
end

class Class2 < Class1
end

p Class2.ancestors - Object.ancestors # [Class2, Class1]

Class1.include Mod1

p Class2.ancestors - Object.ancestors # [Class2, Class1, Mod1]

Mod1.include Mod2

p Mod1.ancestors - Object.ancestors # [Mod1, Mod2]

p Class2.ancestors - Object.ancestors # [Class2, Class1, Mod1]
```
________________________________________________________________

note that descendants of a class do gain its future ancestors

so 2 issues:

1. It would seem natural that in dynamic language, dynamically added ancestors should propagate to descendants
2. Why is there a difference in ancestor propagation between modules and classes
 

---Files--------------------------------
include-future-ancestors-9573.patch (3.49 KB)
prepend-future-ancestors-9573.patch (6.42 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>