aboutsummaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-03 00:39:26 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-03 00:39:26 +0000
commit5d3a54a8505fcfb555a4807f185cec78e5de7269 (patch)
tree479ee59d1081e83e1ff30e889c53c248a825d8df /eval.c
parentfe0a9ac4c4caa000ee7e9402d32b894581ebf492 (diff)
downloadruby-5d3a54a8505fcfb555a4807f185cec78e5de7269.tar.gz
The superclass of a refinement should have BasicObject as its ancestor.
Otherwise, VM_ASSERT(callable_method_entry_p(cme)) in prepare_callable_method_entry() fails if VM_CHECK_MODE is 2. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/eval.c b/eval.c
index 0a8d32eb2f..7118c1556f 100644
--- a/eval.c
+++ b/eval.c
@@ -1273,6 +1273,18 @@ hidden_identity_hash_new(void)
return hash;
}
+static VALUE
+refinement_superclass(VALUE superclass)
+{
+ if (RB_TYPE_P(superclass, T_MODULE)) {
+ /* FIXME: Should ancestors of superclass be used here? */
+ return rb_include_class_new(superclass, rb_cBasicObject);
+ }
+ else {
+ return superclass;
+ }
+}
+
/*!
* \private
* \todo can be static?
@@ -1304,10 +1316,7 @@ rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module)
}
}
FL_SET(module, RMODULE_IS_OVERLAID);
- if (RB_TYPE_P(superclass, T_MODULE)) {
- superclass = rb_include_class_new(superclass,
- RCLASS_SUPER(superclass));
- }
+ superclass = refinement_superclass(superclass);
c = iclass = rb_include_class_new(module, superclass);
RCLASS_REFINED_CLASS(c) = klass;
@@ -1402,10 +1411,7 @@ add_activated_refinement(VALUE activated_refinements,
}
}
FL_SET(refinement, RMODULE_IS_OVERLAID);
- if (RB_TYPE_P(superclass, T_MODULE)) {
- superclass = rb_include_class_new(superclass,
- RCLASS_SUPER(superclass));
- }
+ superclass = refinement_superclass(superclass);
c = iclass = rb_include_class_new(refinement, superclass);
RCLASS_REFINED_CLASS(c) = klass;
refinement = RCLASS_SUPER(refinement);
@@ -1460,13 +1466,9 @@ rb_mod_refine(VALUE module, VALUE klass)
}
refinement = rb_hash_lookup(refinements, klass);
if (NIL_P(refinement)) {
+ VALUE superclass = refinement_superclass(klass);
refinement = rb_module_new();
- if (RB_TYPE_P(klass, T_MODULE)) {
- rb_include_module(refinement, klass);
- }
- else {
- RCLASS_SET_SUPER(refinement, klass);
- }
+ RCLASS_SET_SUPER(refinement, superclass);
FL_SET(refinement, RMODULE_IS_REFINEMENT);
CONST_ID(id_refined_class, "__refined_class__");
rb_ivar_set(refinement, id_refined_class, klass);