ruby-changes:42931
From: nobu <ko1@a...>
Date: Sun, 15 May 2016 10:57:34 +0900 (JST)
Subject: [ruby-changes:42931] nobu:r55005 (trunk): vm_insnhelper.c: deprecated constant in class
nobu 2016-05-15 10:57:28 +0900 (Sun, 15 May 2016) New Revision: 55005 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55005 Log: 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] Modified files: trunk/ChangeLog trunk/test/ruby/test_module.rb trunk/variable.c trunk/vm_insnhelper.c Index: ChangeLog =================================================================== --- ChangeLog (revision 55004) +++ ChangeLog (revision 55005) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun May 15 10:57:26 2016 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * iseq.h (struct iseq_compile_data): use struct rb_id_table Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 55004) +++ vm_insnhelper.c (revision 55005) @@ -664,6 +664,7 @@ vm_get_iclass(rb_control_frame_t *cfp, V https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L664 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 o https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L691 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; Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 55004) +++ test/ruby/test_module.rb (revision 55005) @@ -1415,6 +1415,8 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1415 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 Index: variable.c =================================================================== --- variable.c (revision 55004) +++ variable.c (revision 55005) @@ -2221,6 +2221,20 @@ rb_autoload_p(VALUE mod, ID id) https://github.com/ruby/ruby/blob/trunk/variable.c#L2221 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 e https://github.com/ruby/ruby/blob/trunk/variable.c#L2252 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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/