mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
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
This commit is contained in:
parent
5e7167f8fb
commit
7387c08373
5 changed files with 39 additions and 3 deletions
13
variable.c
13
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue