aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-08 04:44:51 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-08 04:44:51 +0000
commit02eab00b30bcc74c989804fde466c704c19aa138 (patch)
treea59f1fed74ba4b8c2de1fada66f01edd0c333547
parent13f8d7ff8e5b937ed2c7c6eb5afeae217b154d64 (diff)
downloadruby-02eab00b30bcc74c989804fde466c704c19aa138.tar.gz
* insns.def (setclassvariable, setconstant): warn when self is a
refinement. [Bug #10103] [ruby-core:64143] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56101 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--insns.def2
-rw-r--r--test/ruby/test_refinement.rb16
-rw-r--r--vm_insnhelper.c8
4 files changed, 31 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index aa129c7d4c..1a15f8d65c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Sep 8 13:41:46 2016 Shugo Maeda <shugo@ruby-lang.org>
+
+ * insns.def (setclassvariable, setconstant): warn when self is a
+ refinement. [Bug #10103] [ruby-core:64143]
+
Thu Sep 8 11:29:00 2016 Kenta Murata <mrkn@mrkn.jp>
* hash.c (rb_hash_transform_values, rb_hash_transform_values_bang):
diff --git a/insns.def b/insns.def
index f895af7a5b..ac53f967c1 100644
--- a/insns.def
+++ b/insns.def
@@ -173,6 +173,7 @@ setclassvariable
(VALUE val)
()
{
+ vm_ensure_not_refinement_module(GET_SELF());
rb_cvar_set(vm_get_cvar_base(rb_vm_get_cref(GET_EP()), GET_CFP()), id, val);
}
@@ -217,6 +218,7 @@ setconstant
()
{
vm_check_if_namespace(cbase);
+ vm_ensure_not_refinement_module(GET_SELF());
rb_const_set(cbase, id, val);
}
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb
index 13f2d7a353..5980280235 100644
--- a/test/ruby/test_refinement.rb
+++ b/test/ruby/test_refinement.rb
@@ -1674,6 +1674,22 @@ class TestRefinement < Test::Unit::TestCase
assert_equal [ref::RefB, ref::RefA], ref::Combined::USED_REFS
end
+ def test_warn_setconst_in_refinmenet
+ bug10103 = '[ruby-core:64143] [Bug #10103]'
+ warnings = [
+ "-:3: warning: not defined at the refinement, but at the outer class/module",
+ "-:4: warning: not defined at the refinement, but at the outer class/module"
+ ]
+ assert_in_out_err([], <<-INPUT, [], warnings, bug10103)
+ module M
+ refine String do
+ FOO = 123
+ @@foo = 456
+ end
+ end
+ INPUT
+ end
+
private
def eval_using(mod, s)
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 7169a0f7c1..b4db670b74 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -733,6 +733,14 @@ vm_check_if_namespace(VALUE klass)
}
}
+static inline void
+vm_ensure_not_refinement_module(VALUE self)
+{
+ if (RB_TYPE_P(self, T_MODULE) && FL_TEST(self, RMODULE_IS_REFINEMENT)) {
+ rb_warn("not defined at the refinement, but at the outer class/module");
+ }
+}
+
static inline VALUE
vm_get_iclass(rb_control_frame_t *cfp, VALUE klass)
{