diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-07-06 13:56:58 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-07-06 13:56:58 +0000 |
commit | 7387c08373a9421356da2581b1035903ac0a301a (patch) | |
tree | a4e3baed84a314430ecdb21402c3081404edaadd /variable.c | |
parent | 5e7167f8fb954ec46eb12a4a0a1191a8f7d9543d (diff) |
const_missing on private constants
* variable.c (rb_const_search): call #const_missing method on
private constants, as well as uninitialized constants.
[Feature #14328]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63871 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r-- | variable.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/variable.c b/variable.c index ee842e5842..9afed854ae 100644 --- a/variable.c +++ b/variable.c @@ -1795,7 +1795,12 @@ rb_const_missing(VALUE klass, VALUE name) VALUE rb_mod_const_missing(VALUE klass, VALUE name) { + VALUE ref = GET_EC()->private_const_reference; rb_vm_pop_cfunc_frame(); + if (ref) { + rb_name_err_raise("private constant %2$s::%1$s referenced", + ref, name); + } uninitialized_constant(klass, name); UNREACHABLE; @@ -2363,8 +2368,8 @@ 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)) { if (BUILTIN_TYPE(tmp) == T_ICLASS) tmp = RBASIC(tmp)->klass; - rb_name_err_raise("private constant %2$s::%1$s referenced", - tmp, ID2SYM(id)); + GET_EC()->private_const_reference = tmp; + return Qundef; } rb_const_warn_if_deprecated(ce, tmp, id); value = ce->value; @@ -2376,7 +2381,7 @@ rb_const_search(VALUE klass, ID id, int exclude, int recurse, int visibility) continue; } if (exclude && tmp == rb_cObject && klass != rb_cObject) { - return Qundef; + goto not_found; } return value; } @@ -2389,6 +2394,8 @@ rb_const_search(VALUE klass, ID id, int exclude, int recurse, int visibility) goto retry; } + not_found: + GET_EC()->private_const_reference = 0; return Qundef; } |