Project

General

Profile

Bug #7844 ยป include-after-origin-7844.patch

jeremyevans0 (Jeremy Evans), 08/08/2019 05:05 PM

View differences:

class.c
895 895
    struct rb_id_table *const klass_m_tbl = RCLASS_M_TBL(RCLASS_ORIGIN(klass));
896 896

  
897 897
    while (module) {
898
	int origin_seen = FALSE;
898 899
	int superclass_seen = FALSE;
899 900
	struct rb_id_table *tbl;
900 901

  
902
        if (klass == c)
903
            origin_seen = TRUE;
901 904
	if (RCLASS_ORIGIN(module) != module)
902 905
	    goto skip;
903 906
	if (klass_m_tbl && klass_m_tbl == RCLASS_M_TBL(module))
......
905 908
	/* ignore if the module included already in superclasses */
906 909
	for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {
907 910
	    int type = BUILTIN_TYPE(p);
911
            if (c == p)
912
                origin_seen = TRUE;
908 913
	    if (type == T_ICLASS) {
909 914
		if (RCLASS_M_TBL(p) == RCLASS_M_TBL(module)) {
910
		    if (!superclass_seen) {
915
		    if (!superclass_seen && origin_seen) {
911 916
			c = p;  /* move insertion point */
912 917
		    }
913 918
		    goto skip;
test/ruby/test_module.rb
469 469
    assert_equal([Comparable, Kernel], String.included_modules - mixins)
470 470
  end
471 471

  
472
  def test_include_with_prepend
473
    c = Class.new{def m; [:c] end}
474
    p = Module.new{def m; [:p] + super end}
475
    q = Module.new{def m; [:q] + super end; include p}
476
    r = Module.new{def m; [:r] + super end; prepend q}
477
    s = Module.new{def m; [:s] + super end; include r}
478
    a = Class.new(c){def m; [:a] + super end; prepend p; include s}
479
    assert_equal([:p, :a, :s, :q, :r, :c], a.new.m)
480
  end
481

  
472 482
  def test_instance_methods
473 483
    assert_equal([:user, :user2], User.instance_methods(false).sort)
474 484
    assert_equal([:user, :user2, :mixin].sort, User.instance_methods(true).sort)
475
-