summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--internal.h1
-rw-r--r--lib/e2mmap.rb1
-rw-r--r--object.c17
-rw-r--r--test/ruby/test_module.rb4
-rw-r--r--variable.c20
-rw-r--r--version.h2
7 files changed, 38 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 3fe44c32d6..284eb61051 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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)
diff --git a/object.c b/object.c
index 7f0ce7565e..42a3f770ed 100644
--- a/object.c
+++ b/object.c
@@ -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
diff --git a/version.h b/version.h
index ca69a26b8e..2ffea53bde 100644
--- a/version.h
+++ b/version.h
@@ -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"