@@ -1129,7 +1129,7 @@ rb_mod_include(int argc, VALUE *argv, VALUE module)
11291129 CONST_ID (id_append_features , "append_features" );
11301130 CONST_ID (id_included , "included" );
11311131
1132- if (FL_TEST (module , RMODULE_IS_REFINEMENT )) {
1132+ if (BUILTIN_TYPE ( module ) == T_MODULE && FL_TEST (module , RMODULE_IS_REFINEMENT )) {
11331133 rb_raise (rb_eTypeError , "Refinement#include has been removed" );
11341134 }
11351135
@@ -1183,7 +1183,7 @@ rb_mod_prepend(int argc, VALUE *argv, VALUE module)
11831183 int i ;
11841184 ID id_prepend_features , id_prepended ;
11851185
1186- if (FL_TEST (module , RMODULE_IS_REFINEMENT )) {
1186+ if (BUILTIN_TYPE ( module ) == T_MODULE && FL_TEST (module , RMODULE_IS_REFINEMENT )) {
11871187 rb_raise (rb_eTypeError , "Refinement#prepend has been removed" );
11881188 }
11891189
@@ -1264,7 +1264,6 @@ rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module)
12641264 }
12651265 }
12661266 }
1267- FL_SET (module , RMODULE_IS_OVERLAID );
12681267 superclass = refinement_superclass (superclass );
12691268 c = iclass = rb_include_class_new (module , superclass );
12701269 RB_OBJ_WRITE (c , & RCLASS_REFINED_CLASS (c ), klass );
@@ -1273,7 +1272,6 @@ rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module)
12731272
12741273 module = RCLASS_SUPER (module );
12751274 while (module && module != klass ) {
1276- FL_SET (module , RMODULE_IS_OVERLAID );
12771275 c = RCLASS_SET_SUPER (c , rb_include_class_new (module , RCLASS_SUPER (c )));
12781276 RB_OBJ_WRITE (c , & RCLASS_REFINED_CLASS (c ), klass );
12791277 module = RCLASS_SUPER (module );
@@ -1362,13 +1360,11 @@ add_activated_refinement(VALUE activated_refinements,
13621360 c = RCLASS_SUPER (c );
13631361 }
13641362 }
1365- FL_SET (refinement , RMODULE_IS_OVERLAID );
13661363 superclass = refinement_superclass (superclass );
13671364 c = iclass = rb_include_class_new (refinement , superclass );
13681365 RB_OBJ_WRITE (c , & RCLASS_REFINED_CLASS (c ), klass );
13691366 refinement = RCLASS_SUPER (refinement );
13701367 while (refinement && refinement != klass ) {
1371- FL_SET (refinement , RMODULE_IS_OVERLAID );
13721368 c = RCLASS_SET_SUPER (c , rb_include_class_new (refinement , RCLASS_SUPER (c )));
13731369 RB_OBJ_WRITE (c , & RCLASS_REFINED_CLASS (c ), klass );
13741370 refinement = RCLASS_SUPER (refinement );
@@ -1421,6 +1417,7 @@ rb_mod_refine(VALUE module, VALUE klass)
14211417 VALUE superclass = refinement_superclass (klass );
14221418 refinement = rb_refinement_new ();
14231419 RCLASS_SET_SUPER (refinement , superclass );
1420+ RUBY_ASSERT (BUILTIN_TYPE (refinement ) == T_MODULE );
14241421 FL_SET (refinement , RMODULE_IS_REFINEMENT );
14251422 CONST_ID (id_refined_class , "__refined_class__" );
14261423 rb_ivar_set (refinement , id_refined_class , klass );
@@ -1511,7 +1508,7 @@ used_modules_i(VALUE _, VALUE mod, VALUE ary)
15111508{
15121509 ID id_defined_at ;
15131510 CONST_ID (id_defined_at , "__defined_at__" );
1514- while (FL_TEST (rb_class_of (mod ), RMODULE_IS_REFINEMENT )) {
1511+ while (BUILTIN_TYPE ( rb_class_of ( mod )) == T_MODULE && FL_TEST (rb_class_of (mod ), RMODULE_IS_REFINEMENT )) {
15151512 rb_ary_push (ary , rb_attr_get (rb_class_of (mod ), id_defined_at ));
15161513 mod = RCLASS_SUPER (mod );
15171514 }
@@ -1562,7 +1559,7 @@ rb_mod_s_used_modules(VALUE _)
15621559static int
15631560used_refinements_i (VALUE _ , VALUE mod , VALUE ary )
15641561{
1565- while (FL_TEST (rb_class_of (mod ), RMODULE_IS_REFINEMENT )) {
1562+ while (BUILTIN_TYPE ( rb_class_of ( mod )) == T_MODULE && FL_TEST (rb_class_of (mod ), RMODULE_IS_REFINEMENT )) {
15661563 rb_ary_push (ary , rb_class_of (mod ));
15671564 mod = RCLASS_SUPER (mod );
15681565 }
0 commit comments