From a3cc3cc5c958e6e0bb9d650f396123d719c75ca3 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 9 Sep 2016 01:07:41 +0000 Subject: variable.c: fix private constant message * variable.c (rb_const_search): raise with the actual class/module name which defines the private constant. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- variable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'variable.c') diff --git a/variable.c b/variable.c index 0966685690..277edb83b4 100644 --- a/variable.c +++ b/variable.c @@ -2261,7 +2261,7 @@ 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); value = ce->value; -- cgit v1.2.3 From 6054e6d65e1da1362971ee2f7eaa11ea018a0663 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 9 Sep 2016 01:10:01 +0000 Subject: variable.c: fix deprecated constant message * variable.c (rb_const_search): warn with the actual class/module name which defines the deprecated constant. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- variable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'variable.c') diff --git a/variable.c b/variable.c index 277edb83b4..2465212ab9 100644 --- a/variable.c +++ b/variable.c @@ -2263,7 +2263,7 @@ rb_const_search(VALUE klass, ID id, int exclude, int recurse, int visibility) rb_name_err_raise("private constant %2$s::%1$s referenced", 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; -- cgit v1.2.3 From e6a260ecdbe57d14ae01e6c03977775af574b132 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 9 Sep 2016 03:02:22 +0000 Subject: variable.c: rb_deprecate_constant * variable.c (rb_deprecate_constant): new function to deprecate a constant by the name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- variable.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'variable.c') diff --git a/variable.c b/variable.c index 2465212ab9..e9245050d3 100644 --- a/variable.c +++ b/variable.c @@ -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 -- cgit v1.2.3