diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-09 03:44:13 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-09 03:44:13 +0000 |
commit | a4a4e8b5a05f69cec077e72a43769e38ef205e23 (patch) | |
tree | d9d86c1762afea014726d3f456a5f4a7c3984e05 | |
parent | 277d1f50bb04b9c8f84311ba8de6568dd3347e36 (diff) | |
parent | 4785df5527497f03a08085fd2b799fe3d5da87c9 (diff) |
add tag v2_4_0_preview2
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v2_4_0_preview2@56122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | internal.h | 1 | ||||
-rw-r--r-- | lib/e2mmap.rb | 1 | ||||
-rw-r--r-- | object.c | 17 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 4 | ||||
-rw-r--r-- | variable.c | 20 | ||||
-rw-r--r-- | version.h | 2 |
7 files changed, 38 insertions, 15 deletions
@@ -1,3 +1,11 @@ +Fri Sep 9 10:10:00 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * variable.c (rb_const_search): warn with the actual class/module + name which defines the deprecated constant. + + * variable.c (rb_const_search): raise with the actual class/module + name which defines the private constant. + Thu Sep 8 17:47:18 2016 Kazuki Tsujimoto <kazuki@callcc.net> * array.c (flatten): use rb_obj_class instead of rb_class_of diff --git a/internal.h b/internal.h index f9bc693e0f..bf3880e695 100644 --- a/internal.h +++ b/internal.h @@ -1498,6 +1498,7 @@ VALUE rb_search_class_path(VALUE); VALUE rb_attr_delete(VALUE, ID); VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef); void rb_autoload_str(VALUE mod, ID id, VALUE file); +void rb_deprecate_constant(VALUE mod, const char *name); /* version.c */ extern const char ruby_engine[]; diff --git a/lib/e2mmap.rb b/lib/e2mmap.rb index a9990b5ec5..bbff4f8c2e 100644 --- a/lib/e2mmap.rb +++ b/lib/e2mmap.rb @@ -128,7 +128,6 @@ module Exception2MessageMapper # define exception named ``c'' with message m. # def E2MM.def_exception(k, n, m, s = StandardError) - n = n.id2name if n.kind_of?(Fixnum) e = Class.new(s) E2MM.instance_eval{@MessageMap[[k, e]] = m} k.const_set(n, e) @@ -3512,9 +3512,10 @@ InitVM_Object(void) rb_undef_alloc_func(rb_cNilClass); rb_undef_method(CLASS_OF(rb_cNilClass), "new"); /* - * An alias of +nil+ + * An obsolete alias of +nil+ */ rb_define_global_const("NIL", Qnil); + rb_deprecate_constant(rb_cObject, "NIL"); rb_define_method(rb_cModule, "freeze", rb_mod_freeze, 0); rb_define_method(rb_cModule, "===", rb_mod_eqq, 1); @@ -3596,9 +3597,10 @@ InitVM_Object(void) rb_undef_alloc_func(rb_cTrueClass); rb_undef_method(CLASS_OF(rb_cTrueClass), "new"); /* - * An alias of +true+ + * An obsolete alias of +true+ */ rb_define_global_const("TRUE", Qtrue); + rb_deprecate_constant(rb_cObject, "TRUE"); rb_cFalseClass = rb_define_class("FalseClass", rb_cObject); rb_define_method(rb_cFalseClass, "to_s", false_to_s, 0); @@ -3610,17 +3612,10 @@ InitVM_Object(void) rb_undef_alloc_func(rb_cFalseClass); rb_undef_method(CLASS_OF(rb_cFalseClass), "new"); /* - * An alias of +false+ + * An obsolete alias of +false+ */ rb_define_global_const("FALSE", Qfalse); - - { - VALUE names[3]; - names[0] = ID2SYM(rb_intern_const("TRUE")); - names[1] = ID2SYM(rb_intern_const("FALSE")); - names[2] = ID2SYM(rb_intern_const("NIL")); - rb_mod_deprecate_constant(3, names, rb_cObject); - } + rb_deprecate_constant(rb_cObject, "FALSE"); } void diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 0f9351c57d..e9529273eb 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1360,6 +1360,9 @@ class TestModule < Test::Unit::TestCase c.const_set(:FOO, "foo") $VERBOSE = verbose assert_raise(NameError) { c::FOO } + assert_raise_with_message(NameError, /#{c}::FOO/) do + Class.new(c)::FOO + end end def test_private_constant2 @@ -1417,6 +1420,7 @@ class TestModule < Test::Unit::TestCase c.const_set(:FOO, "foo") c.deprecate_constant(:FOO) assert_warn(/deprecated/) {c::FOO} + assert_warn(/#{c}::FOO is deprecated/) {Class.new(c)::FOO} bug12382 = '[ruby-core:75505] [Bug #12382]' assert_warn(/deprecated/, bug12382) {c.class_eval "FOO"} end diff --git a/variable.c b/variable.c index 0966685690..e9245050d3 100644 --- a/variable.c +++ b/variable.c @@ -2261,9 +2261,9 @@ rb_const_search(VALUE klass, ID id, int exclude, int recurse, int visibility) while ((ce = rb_const_lookup(tmp, id))) { if (visibility && RB_CONST_PRIVATE_P(ce)) { rb_name_err_raise("private constant %2$s::%1$s referenced", - klass, ID2SYM(id)); + tmp, ID2SYM(id)); } - rb_const_warn_if_deprecated(ce, klass, id); + rb_const_warn_if_deprecated(ce, tmp, id); value = ce->value; if (value == Qundef) { if (am == tmp) break; @@ -2732,6 +2732,22 @@ set_const_visibility(VALUE mod, int argc, const VALUE *argv, rb_clear_constant_cache(); } +void +rb_deprecate_constant(VALUE mod, const char *name) +{ + rb_const_entry_t *ce; + ID id; + long len = strlen(name); + + rb_frozen_class_p(mod); + if (!(id = rb_check_id_cstr(name, len, NULL)) || + !(ce = rb_const_lookup(mod, id))) { + rb_name_err_raise("constant %2$s::%1$s not defined", + mod, rb_fstring_new(name, len)); + } + ce->flag |= CONST_DEPRECATED; +} + /* * call-seq: * mod.private_constant(symbol, ...) => mod @@ -4,7 +4,7 @@ #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 9 -#define RUBY_RELEASE_DAY 8 +#define RUBY_RELEASE_DAY 9 #include "ruby/version.h" |