1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/ruby/core/module
Jeremy Evans 98286e9850 Ensure origins for all included, prepended, and refined modules
This fixes various issues when a module is included in or prepended
to a module or class, and then refined, or refined and then included
or prepended to a module or class.

Implement by renaming ensure_origin to rb_ensure_origin, making it
non-static, and calling it when refining a module.

Fix Module#initialize_copy to handle origins correctly.  Previously,
Module#initialize_copy did not handle origins correctly.  For example,
this code:

```ruby
module B; end
class A
  def b; 2 end
  prepend B
end
a = A.dup.new
class A
  def b; 1 end
end
p a.b
```

Printed 1 instead of 2.  This is because the super chain for
a.singleton_class was:

```
a.singleton_class
A.dup
B(iclass)
B(iclass origin)
A(origin) # not A.dup(origin)
```

The B iclasses would not be modified, so the includer entry would be
still be set to A and not A.dup.

This modifies things so that if the class/module has an origin,
all iclasses between the class/module and the origin are duplicated
and have the correct includer entry set, and the correct origin
is created.

This requires other changes to make sure all tests still pass:

* rb_undef_methods_from doesn't automatically handle classes with
  origins, so pass it the origin for Comparable when undefing
  methods in Complex. This fixed a failure in the Complex tests.

* When adding a method, the method cache was not cleared
  correctly if klass has an origin.  Clear the method cache for
  the klass before switching to the origin of klass.  This fixed
  failures in the autoload tests related to overridding require,
  without breaking the optimization tests.  Also clear the method
  cache for both the module and origin when removing a method.

* Module#include? is fixed to skip origin iclasses.

* Refinements are fixed to use the origin class of the module that
  has an origin.

* RCLASS_REFINED_BY_ANY is removed as it was only used in a single
  place and is no longer needed.

* Marshal#dump is fixed to skip iclass origins.

* rb_method_entry_make is fixed to handled overridden optimized
  methods for modules that have origins.

Fixes [Bug #16852]
2020-06-03 09:50:37 -07:00
..
fixtures Update to ruby/spec@4e486fa 2020-05-31 18:22:49 +02:00
shared Update to ruby/spec@41bf282 2020-02-28 19:07:17 +01:00
alias_method_spec.rb Drop support for ruby 2.4 from ruby/spec 2020-04-01 15:36:20 +09:00
allocate_spec.rb
ancestors_spec.rb
append_features_spec.rb Use FrozenError instead of frozen_error_class 2020-04-01 15:36:20 +09:00
attr_accessor_spec.rb Drop support for ruby 2.4 from ruby/spec 2020-04-01 15:36:20 +09:00
attr_reader_spec.rb Drop support for ruby 2.4 from ruby/spec 2020-04-01 15:36:20 +09:00
attr_spec.rb Drop support for ruby 2.4 from ruby/spec 2020-04-01 15:36:20 +09:00
attr_writer_spec.rb Drop support for ruby 2.4 from ruby/spec 2020-04-01 15:36:20 +09:00
autoload_spec.rb Update to ruby/spec@4e486fa 2020-05-31 18:22:49 +02:00
case_compare_spec.rb
class_eval_spec.rb
class_exec_spec.rb
class_variable_defined_spec.rb
class_variable_get_spec.rb
class_variable_set_spec.rb Use FrozenError instead of frozen_error_class 2020-04-01 15:36:20 +09:00
class_variables_spec.rb
comparison_spec.rb
const_defined_spec.rb
const_get_spec.rb
const_missing_spec.rb
const_set_spec.rb Use FrozenError instead of frozen_error_class 2020-04-01 15:36:20 +09:00
constants_spec.rb
define_method_spec.rb Drop support for ruby 2.4 from ruby/spec 2020-04-01 15:36:20 +09:00
define_singleton_method_spec.rb
deprecate_constant_spec.rb
eql_spec.rb
equal_spec.rb
equal_value_spec.rb
extend_object_spec.rb
extended_spec.rb
freeze_spec.rb
gt_spec.rb
gte_spec.rb
include_spec.rb
included_modules_spec.rb
included_spec.rb Update to ruby/spec@032ee74 2020-05-03 12:28:29 +02:00
initialize_copy_spec.rb
initialize_spec.rb
instance_method_spec.rb
instance_methods_spec.rb
lt_spec.rb
lte_spec.rb
method_added_spec.rb
method_defined_spec.rb
method_removed_spec.rb
method_undefined_spec.rb
module_eval_spec.rb
module_exec_spec.rb
module_function_spec.rb
name_spec.rb Update to ruby/spec@032ee74 2020-05-03 12:28:29 +02:00
nesting_spec.rb
new_spec.rb
prepend_features_spec.rb
prepend_spec.rb Ensure origins for all included, prepended, and refined modules 2020-06-03 09:50:37 -07:00
prepended_spec.rb
private_class_method_spec.rb
private_constant_spec.rb
private_instance_methods_spec.rb
private_method_defined_spec.rb
private_spec.rb
protected_instance_methods_spec.rb
protected_method_defined_spec.rb
protected_spec.rb
public_class_method_spec.rb
public_constant_spec.rb
public_instance_method_spec.rb
public_instance_methods_spec.rb
public_method_defined_spec.rb
public_spec.rb
refine_spec.rb Drop support for ruby 2.4 from ruby/spec 2020-04-01 15:36:20 +09:00
remove_class_variable_spec.rb
remove_const_spec.rb
remove_method_spec.rb Drop support for ruby 2.4 from ruby/spec 2020-04-01 15:36:20 +09:00
singleton_class_spec.rb Update to ruby/spec@032ee74 2020-05-03 12:28:29 +02:00
to_s_spec.rb
undef_method_spec.rb Drop support for ruby 2.4 from ruby/spec 2020-04-01 15:36:20 +09:00
using_spec.rb Update to ruby/spec@d394dfd 2020-05-02 16:03:14 +02:00