summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-15 01:57:28 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-15 01:57:28 (GMT)
commit5cb5692ac8758420ddb7b5bdae337f2338d91b26 (patch)
tree5c8e1ef5ecb2b18d112ae5992f59470b0a2e116e
parent6d4fb98e59e74bb23329314482ef8012bf90aa92 (diff)
vm_insnhelper.c: deprecated constant in class
* vm_insnhelper.c (vm_get_ev_const): warn deprecated constant even in the class context. [ruby-core:75505] [Bug #12382] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--test/ruby/test_module.rb2
-rw-r--r--variable.c24
-rw-r--r--vm_insnhelper.c2
4 files changed, 24 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index cb15973..1d95160 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun May 15 10:57:26 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * vm_insnhelper.c (vm_get_ev_const): warn deprecated constant even
+ in the class context. [ruby-core:75505] [Bug #12382]
+
Sun May 15 03:13:01 2016 NARUSE, Yui <naruse@ruby-lang.org>
* iseq.h (struct iseq_compile_data): use struct rb_id_table
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 5bb62d7..4ca79a7 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -1415,6 +1415,8 @@ class TestModule < Test::Unit::TestCase
c.const_set(:FOO, "foo")
c.deprecate_constant(:FOO)
assert_warn(/deprecated/) {c::FOO}
+ bug12382 = '[ruby-core:75505] [Bug #12382]'
+ assert_warn(/deprecated/, bug12382) {c.class_eval "FOO"}
end
def test_constants_with_private_constant
diff --git a/variable.c b/variable.c
index 9c3ce2d..db26268 100644
--- a/variable.c
+++ b/variable.c
@@ -2221,6 +2221,20 @@ rb_autoload_p(VALUE mod, ID id)
return (ele = check_autoload_data(load)) ? ele->feature : Qnil;
}
+void
+rb_const_warn_if_deprecated(const rb_const_entry_t *ce, VALUE klass, ID id)
+{
+ if (RB_CONST_DEPRECATED_P(ce)) {
+ if (klass == rb_cObject) {
+ rb_warn("constant ::%"PRIsVALUE" is deprecated", QUOTE_ID(id));
+ }
+ else {
+ rb_warn("constant %"PRIsVALUE"::%"PRIsVALUE" is deprecated",
+ rb_class_name(klass), QUOTE_ID(id));
+ }
+ }
+}
+
static VALUE
rb_const_get_0(VALUE klass, ID id, int exclude, int recurse, int visibility)
{
@@ -2238,15 +2252,7 @@ rb_const_get_0(VALUE klass, ID id, int exclude, int recurse, int visibility)
rb_name_err_raise("private constant %2$s::%1$s referenced",
klass, ID2SYM(id));
}
- if (RB_CONST_DEPRECATED_P(ce)) {
- if (klass == rb_cObject) {
- rb_warn("constant ::%"PRIsVALUE" is deprecated", QUOTE_ID(id));
- }
- else {
- rb_warn("constant %"PRIsVALUE"::%"PRIsVALUE" is deprecated",
- rb_class_name(klass), QUOTE_ID(id));
- }
- }
+ rb_const_warn_if_deprecated(ce, klass, id);
value = ce->value;
if (value == Qundef) {
if (am == tmp) break;
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index dc43d88..403b24b 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -664,6 +664,7 @@ vm_get_iclass(rb_control_frame_t *cfp, VALUE klass)
static inline VALUE
vm_get_ev_const(rb_thread_t *th, VALUE orig_klass, ID id, int is_defined)
{
+ void rb_const_warn_if_deprecated(const rb_const_entry_t *ce, VALUE klass, ID id);
VALUE val;
if (orig_klass == Qnil) {
@@ -690,6 +691,7 @@ vm_get_ev_const(rb_thread_t *th, VALUE orig_klass, ID id, int is_defined)
rb_const_entry_t *ce;
search_continue:
if ((ce = rb_const_lookup(klass, id))) {
+ rb_const_warn_if_deprecated(ce, klass, id);
val = ce->value;
if (val == Qundef) {
if (am == klass) break;