summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-30 14:05:14 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-30 14:05:14 +0000
commit6334ff3858d7dc5b484079e1a15624f2b0bd2454 (patch)
tree0156deaaa9c9d43e7639a525b09999e586123c9d /class.c
parentc884cbd810d4a8b331e17aede4760a2368261177 (diff)
merge revision(s) 58082,58083: [Backport #13236]
class.c: ensure_includable * class.c (ensure_includable): extract checks to include and prepend. class.c: prohibit refinement module * class.c (ensure_includable): cannot include refinement module, or the type and the class do not match. [ruby-core:79632] [Bug #13236] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@58519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/class.c b/class.c
index a5f4894b35..31b83137d4 100644
--- a/class.c
+++ b/class.c
@@ -846,18 +846,23 @@ rb_include_class_new(VALUE module, VALUE super)
static int include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super);
+static void
+ensure_includable(VALUE klass, VALUE module)
+{
+ rb_frozen_class_p(klass);
+ Check_Type(module, T_MODULE);
+ if (!NIL_P(rb_refinement_module_get_refined_class(module))) {
+ rb_raise(rb_eArgError, "refinement module is not allowed");
+ }
+ OBJ_INFECT(klass, module);
+}
+
void
rb_include_module(VALUE klass, VALUE module)
{
int changed = 0;
- rb_frozen_class_p(klass);
-
- if (!RB_TYPE_P(module, T_MODULE)) {
- Check_Type(module, T_MODULE);
- }
-
- OBJ_INFECT(klass, module);
+ ensure_includable(klass, module);
changed = include_modules_at(klass, RCLASS_ORIGIN(klass), module, TRUE);
if (changed < 0)
@@ -962,11 +967,7 @@ rb_prepend_module(VALUE klass, VALUE module)
VALUE origin;
int changed = 0;
- rb_frozen_class_p(klass);
-
- Check_Type(module, T_MODULE);
-
- OBJ_INFECT(klass, module);
+ ensure_includable(klass, module);
origin = RCLASS_ORIGIN(klass);
if (origin == klass) {